I am using ruby and rspec to write automated test cases along with watir.
C:\Users\san\Dragon>gem list 'rspec'
*** LOCAL GEMS ***
rspec (3.4.0, 2.14.1)
rspec-core (3.4.3, 2.14.8)
rspec-expectations (3.4.0, 2.14.5)
rspec-mocks (3.4.1, 2.14.6)
rspec-support (3.4.1)
When I run the test case using following command.
C:\Users\san\Dragon>rspec -f spec\sampletest_spec.rb:65
I got this error
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.3/lib/rspec/core/formatters.rb:173:in `find_formatter': Formatter 'spec\sampletest_spec.rb:65' unknown - maybe you meant 'documentation' or 'progress'?. (ArgumentError)
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-.4.3/lib/rspec/core/formatters.rb:141:in `add'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.3/lib/rspec/core/configuration.rb:767:in `add_formatter'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.3/lib/rspec/core/configuration_options.rb:114:in `block in load_formatters_into'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.3/lib/rspec/core/configuration_options.rb:114:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.3/lib/rspec/core/configuration_options.rb:114:in `load_formatters_into'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.3/lib/rspec/core/configuration_options.rb:23:in `configure'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.3/lib/rspec/core/runner.rb:105:in `setup'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.3/lib/rspec/core/runner.rb:92:in `run'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.3/lib/rspec/core/runner.rb:78:in `run'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.3/lib/rspec/core/runner.rb:45:in `invoke'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.3/exe/rspec:4:in `<top (required)>'
from C:/Ruby193/bin/rspec:23:in `load'
from C:/Ruby193/bin/rspec:23:in `<main>'
Getting same error also for
rspec spec\sampletest_spec.rb --format documentation
rspec --format spec\sampletest_spec.rb
You are messing things up. --format/-f parameter expects the format description itself to be passed to it, while you are passing the name of the test file.
I have no clue, why there are problems with
rspec spec\sampletest_spec.rb --format documentation
this one must work. But anyway, the easiest solution would be to create .rspec file in the project root directory, having the following content:
--format documentation
yes, the only line. As you have this file created, simply run
rspec spec\sampletest_spec.rb
RSpec will read a configuration from this file and apply the desired format.
Related
When I run cucumber, I get the following messages:
*** WARNING: You must use ANSICON 1.31 or higher (http://adoxa.110mb.com/ansicon) to get coloured output on Windows
Warning: you should require 'minitest/autorun' instead.
Warning: or add 'gem "minitest"' before 'require "minitest/autorun"'
From:
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.2.1/lib/cucumber/core_ext/disable_mini_and_test_unit_autorun.rb:3:in `<top (required)>'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.2.1/lib/cucumber/runtime.rb:21:in `initialize'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:40:in `new'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:40:in `execute!'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:20:in `execute'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.2.1/bin/cucumber:14:in `<top (required)>'
C:/RailsInstaller/Ruby2.1.0/bin/cucumber:23:in `load'
C:/RailsInstaller/Ruby2.1.0/bin/cucumber:23:in `<main>'
MiniTest::Unit::TestCase is now Minitest::Test. From C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/test/unit/testcase.rb:8:in `<module:Unit>'
undefined method `_run_suite' for class `Test::Unit::Runner' (NameError)
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/test/unit.rb:676:in `<class:Runner>'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/test/unit.rb:261:in `<module:Unit>'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/test/unit.rb:15:in `<module:Test>'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/test/unit.rb:7:in `<top (required)>'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.2.1/lib/cucumber/core_ext/disable_mini_and_test_unit_autorun.rb:25:in `<top (required)>'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.2.1/lib/cucumber/runtime.rb:21:in `initialize'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:40:in `new'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:40:in `execute!'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:20:in `execute'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/cucumber-1.2.1/bin/cucumber:14:in `<top (required)>'
C:/RailsInstaller/Ruby2.1.0/bin/cucumber:23:in `load'
C:/RailsInstaller/Ruby2.1.0/bin/cucumber:23:in `<main>'
bundle list gives me:
DL is deprecated, please use Fiddle
Gems included by the bundle:
* builder (3.2.2)
* bundler (1.7.7)
* cucumber (1.2.1)
* diff-lcs (1.1.3)
* gherkin (2.11.8)
* json (1.8.1)
* minitest (4.7.5)
* multi_json (1.10.1)
* rspec-expectations (2.11.2)
Based on a similar question on stack exchange, I have the following in `features\support\env.rb':
require 'minitest'
module MiniTestAssertions
def self.extended(base)
base.extend(MiniTest::Assertions)
base.assertions = 0
end
attr_accessor :assertions
end
World(MiniTestAssertions)
What's my next step to getting cucumber working?
Edit:
I've tried running cucumber in a completely empty directory (expecting to get a warning that no features are defined), but get exactly the same message: the warning about minitest, then the error about undefined method '_run_suite'. Evertyhing I can find on the web about this either relates to Rails (which I'm not using) or says it's an old problem that has been fixed, so I'm completely stuck. :(
Any reason why you can't use ruby 1.9 for going through this exercise?
The latest version of the The Cucumber Book - version 3.0 - was released in Mar 2014 when ruby 1.9.3 was the most prevalently used ruby version.
The code for the book was tested with ruby 1.9.3-p194 (as mentioned in Appendix 2 - Installing Cucumber section).
The authors/pragprog may come up with a new edition of the book, and at that time they will ensure the code in the book work with ruby 2.2 or the then most commonly used version of ruby.
It is quite possible to figure out how to make these examples work for ruby 2.0 or higher version, but that is a headache I would recommend you not concern yourself at this time. Given that you are just now starting to learn about cucumber, it would be best to follow the text in the book based on the version it recommends.
After getting familiar with cucumber, and other components of the ruby world, you will appreciate why I find "How do I persuade it to use RSpec?" to be very funny. :-)
As you know, the configuration of your development environment is a tedious and error-prone task. I prefer to work in a *nix-type environment, which you could achieve on your Windows box using, say, VirtualBox or some Docker-for-Windows arrangement.
If you can get such a Docker configuration for Windows up and running, then this may be your best bet to solve the issue quickly, since Docker is all about sharing/reusing pre-configured environments/deployments, which can be a real time-saver! There are already some fine Dockerfile configurations that should help you see which components to install. See: this and that.
BTW, if you prefer to use rspec over minitest (and who wouldn't?), you'll want to use some sample code that doesn't "require 'minitest'". If you only are interested to get the current example working, you might entertain the idea that is given by the error message to "require 'minitest/autorun'". I hope it helps you--good luck!
Trying to run bundle exec rspec spec/models/user_spec.rb but failing to execute (see error below).
Contents of user_spec.rb:
require 'rails_helper'
describe User do
pending "add some examples to (or delete) #{__FILE__}"
end
If I remove the last 3 lines, then it complete with 0 examples and 0 failures. However, when the last 3 lines are present, it generates an error
/spec/models/user_spec.rb:4:in `<top (required)>': uninitialized constant User (NameError)
from /var/lib/gems/1.9.1/gems/rspec-core-3.0.3/lib/rspec/core/configuration.rb:1057:in `load'
from /var/lib/gems/1.9.1/gems/rspec-core-3.0.3/lib/rspec/core/configuration.rb:1057:in `block in load_spec_files'
from /var/lib/gems/1.9.1/gems/rspec-core-3.0.3/lib/rspec/core/configuration.rb:1057:in `each'
from /var/lib/gems/1.9.1/gems/rspec-core-3.0.3/lib/rspec/core/configuration.rb:1057:in `load_spec_files'
from /var/lib/gems/1.9.1/gems/rspec-core-3.0.3/lib/rspec/core/runner.rb:97:in `setup'
from /var/lib/gems/1.9.1/gems/rspec-core-3.0.3/lib/rspec/core/runner.rb:85:in `run'
from /var/lib/gems/1.9.1/gems/rspec-core-3.0.3/lib/rspec/core/runner.rb:70:in `run'
from /var/lib/gems/1.9.1/gems/rspec-core-3.0.3/lib/rspec/core/runner.rb:38:in `invoke'
from /var/lib/gems/1.9.1/gems/rspec-core-3.0.3/exe/rspec:4:in `<top (required)>'
from /usr/local/bin/rspec:23:in `load'
from /usr/local/bin/rspec:23:in `<main>'
It seems it doesn't know what User is and treats it as a constant, when this is infact a model. I have verified in the ruby sandbox that I can create new Users in the database. Any ideas?
Answer:
After removing --warnings from .rspec (thank you kirti), current error was about capybara version being too low (requires 2.2). After installing the latest version (modifying gemfile and bundle install), rspec appears to be executing correctly. Thank you to all for your comments.
I had the same issue, this was due to rspec/rails_helper.rb not being called anywhere.
I added it to the .rspec file, so my file look like this
--color
--require spec_helper
--require rails_helper
This and adding warnings to false in the spec/spec_helper.rb solved it for me !
config.warnings = false
After removing --warnings from .rspec (thank you kirti), current error was about capybara version being too low (requires 2.2). After installing the latest version (modifying gemfile and bundle install), rspec appears to be executing correctly. Thank you to all for your comments.
For me, the issue was that the name of the class was not being correctly called due to it being in another namespace. For example, I had:
RSpec.describe User do
# ... some tests
end
where I should have had
RSpec.describe MyModule::User do
# ... some tests
end
because the user class was defined with the MyModule module.
I am attempting to take an interactive Ruby test to no avail.
I downloaded the zip file with no problems and followed the directions for
the terminal command line where I continue to get the following error. I
am using "Ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin10.8.0]".
If anyone can offer any help or suggestions thank you in advance.
INSTRUCTIONS:
Install RSpec
gem install rspec
Enter the course directory. (That's the same directory that this
index.html file is in.)
cd learn_ruby
Enter the 00_hello lab.
cd 00_hello
Open a terminal in this directory
cd 00_hello
This directory is the starting point for this exercise. It contains a
spec file and you'll be adding a ruby file to (eventually) make the
specs pass.
Run the test
rake
Watch it fail
You should see an error. Don't get scared! Try to read it and figure out
what the computer wants to tell you. Somewhere on the first line it
should say something like
no such file to load -- test-first-teaching/hello/hello (LoadError)
I do not get this error message, I get the one below:
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb,
Rakefile.rb)
/usr/local/rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in `eval'
/usr/local/rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in
`<main>'
(See full trace by running task with --trace)
When I run rake --trace I receive:
rake --trace
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb,
Rakefile.rb)
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/application.rb:632:in
`raw_load_rakefile'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/application.rb:94:in
`block in load_rakefile'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/application.rb:165:in
`standard_exception_handling'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/application.rb:93:in
`load_rakefile'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/application.rb:77:in
`block in run'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/application.rb:165:in
`standard_exception_handling'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/application.rb:75:in
`run'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/bin/rake:33:in
`<top (required)>'
/usr/local/rvm/gems/ruby-1.9.3-p392/bin/rake:19:in `load'
/usr/local/rvm/gems/ruby-1.9.3-p392/bin/rake:19:in `<main>'
/usr/local/rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in `eval'
/usr/local/rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in
`<main>'
you have to cd into your project directory before you can run rake routes
I can't figure out why my RSPEC isn't working. I reinstalled RSPEC with sudo gem install rspec and then tried again to install with a specific version number (sudo gem install rspec -v 2.11.0)
I continue to get the following error message and I cannot figure out what it means. I believe that I may or may not have version 1 also installed, not sure.
Castillo$ rspec document_spec.rb
/Users/Castillo/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
require': no such file to load -- document (LoadError) from
/Users/Castillo/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
require' from /Users/Castillo/Desktop/document_spec.rb:1:in <top
(required)>' from
/Users/Castillo/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:inload' from
/Users/Castillo/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in block in load_spec_files' from
/Users/Castillo/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:inmap' from
/Users/Castillo/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in load_spec_files' from
/Users/Castillo/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:22:inrun' from
/Users/Castillo/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:69:in
run' from
/Users/Castillo/.rvm/gems/ruby-1.9.2-p290/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in
block in autorun'
Add full path to your document.rb file into spec file
or use
require_relative
or
require File.expand_path('../document.rb', __FILE__)
every time i execute rspec, dosen't matter what I have done, if the code is wrong it tells:
nev3rkill#nev3rkill-virtual-machine ~/Documentos/ruby $ rspec
/home/nev3rkill/.rvm/gems/ruby-1.9.2-p318/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load': no such file to load -- /home/nev3rkill/Documentos/ruby/spec (LoadError)
from /home/nev3rkill/.rvm/gems/ruby-1.9.2-p318/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `block in load_spec_files'
from /home/nev3rkill/.rvm/gems/ruby-1.9.2-p318/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `map'
from /home/nev3rkill/.rvm/gems/ruby-1.9.2-p318/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load_spec_files'
from /home/nev3rkill/.rvm/gems/ruby-1.9.2-p318/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:22:in `run'
from /home/nev3rkill/.rvm/gems/ruby-1.9.2-p318/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80:in `run_in_process'
from /home/nev3rkill/.rvm/gems/ruby-1.9.2-p318/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69:in `run'
from /home/nev3rkill/.rvm/gems/ruby-1.9.2-p318/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10:in `block in autorun'
nev3rkill#nev3rkill-virtual-machine ~/Documentos/ruby $
I have tested with a lot of versions, with ruby 1.9.3,1.9.2 but i don't know. Is it normal?
Unless you're in a path with a spec directory (e.g. the root of your rails project), you also need to tell rspec which spec files to run, either by passing it a directory or file. e.g:
$ rspec path/to/specs/
Will run all the specs in the path/to/specs/ path (recursively), or:
$ rspec spec/your_specs.rb
will run the specs in the spec/your_specs.rb file.