I am learning Ruby and have to do some homework, but have problem with executing code. I searched this forum and Google and found that this could be problem with different Ruby versions but I don't know how to fix this. I've tried to execute:
cucumber features/filter_movie_list.feature
and got this:
And I should not see 'G' #
features/step_definitions/movie_steps.rb:32
no such file to load -- rspec/matchers/built_in/has (LoadError)
./features/step_definitions/movie_steps.rb:34:in /^(?:|I )should not see '([^']*)'$/'
features/filter_movie_list.feature:37:inAnd I should not see 'G''
Can someone help me to solve this problem or give me link to solution?
EDIT:
movie_steps.rb relevant for this taks is:
Then /^(?:|I )should not see '([^']*)'$/ do |text|
if page.respond_to? :should
page.find('#movies').should have_no_content(text)
else
assert page.find('#movies').has_no_content?(text)
end
end
The error message says that Cucumber can't find RSpec.
To solve it, edit your Gemfile and add these and that should solve it.
group :test do
gem 'rspec' # Behavior Driven Development (BDD) for Ruby
gem 'rspec-core' # RSpec runner and example groups.
gem 'rspec-expectations' # RSpec matchers for should and should_not.
gem 'rspec-mocks' # RSpec test double framework with stubbing and mocking.
gem 'rspec-rails' # RSpec version 2.x for Rails version 3.x.
end
If that does solve it, you can probably remove all those lines except the first one (the 'rspec' one) because that line should take care of the others.
Related
~/Sites/sample_app$ rails test
Running via Spring preloader in process 24338
Run options: --seed 58780
Running:
..
Finished in 0.292172s, 6.8453 runs/s, 6.8453 assertions/s.
/var/lib/gems/2.3.0/gems/railties-5.1.0/lib/rails/test_unit/minitest_plugin.rb:9:in `aggregated_results': wrong number of arguments (given 1, expected 0) (ArgumentError)
I don't understand why I am getting this error. I Can't seem to find anyone with this specific error. I'm following the tutorial https://www.railstutorial.org/book/static_pages. This error follows the rails test command. Running Ubuntu and rails 5.1 if that helps. I'm not passing any arguments so I don't understand why I am getting this error.
My test file looks like :
require 'test_helper'
class StaticPagesControllerTest < ActionDispatch::IntegrationTest
test "should get home" do
get static_pages_home_url
assert_response :success
end
test "should get help" do
get static_pages_help_url
assert_response :success
end
This is actually a bug in rails, revealed by minitest update to 5.10.2 as said here and it has already been fixed here.
As the pull request is only 10 hours old (at the time of writing), it has not yet been released, although it's already merged.
In the mean time, you can specify in your Gemfile:
gem 'minitest', '~> 5.10', '!= 5.10.2'
Edit
Don't forget to bundle update minitest
Hey I'm doing this exact tutorial and followed the top solution and it fixed my issue, specifically (for us total noobs) I did this to my Gemfile
group :test do
gem 'rails-controller-testing', '0.1.1'
gem 'minitest-reporters', '1.1.9'
gem 'guard', '2.13.0'
gem 'guard-minitest', '2.4.4'
gem 'minitest', '~> 5.10', '!= 5.10.2' # add this here to fix error
end
It turns out that in my test/test_helper.rb I needed a line of code that was missing. I added this before "class ActiveSupport::TestCase".
Minitest::Reporters.use!
This gave me a passing result for my test with no strange argument error. Hope this helps someone for the future!
Problem is in minitest 5.10.2. Downgrading to 5.10.1 fixes it.
Add this line in test group in Gemfile
gem 'minitest', '5.10.1'
Then run following commands
bundle update minitest
rails test
The issue is resolved
I also encountered this error. I tried using the top voted solution, but rails told me that bundle has locked minitest to 5.10.2. Instead, I just did a gem update minitest and my tests ran without the weird error.
I am currently following this tutorial to begin testing rspec with capybara and selenium. I included the necessary gems and ran a bundle install, but cant seem to find the rails_helper.rb to continue with the tutorial.
This is on rails 4.2.4.
Thanks,
Otterman
rails_helper.rb in generated when you run rails g rspec:install. Make sure you are using a relatively recent version of rspec-rails as versions before 3.0 only the spec_helper.rb is used configure the test suite (well by default at least).
The spec_helper.rb file is used to set up RSpec itself and rails_helper.rb sets up the rails stack.
You should be able to find the file in ../spec/rails_helper
As mentioned, I was missing
group :development, :test do
gem 'rspec-rails', '~> 3.0'
end
in my gemfile.
After which I ran
rails generate rspec:install
I just started a new project with RAils 4.2 on ruby 2.1.2. In the Gemfile, it clearly states that pry-byebug is included, and in my ~/.pryrc file I have the following
puts "HELLO!!"
if defined?(Rails) && Rails.env
extend Rails::ConsoleMethods
end
require 'hirb'
Hirb.enable
When I do
$ rails c
I don't see "hellO' being printed and I don't get Hirb's pretty format
Any chance someone can tell me where should I start looking where the error might be?
Thank you!
I had to include gem 'pry-rails' in my Gemfile, and not within any groups.
TL; DR:
I don't know how to get RSpec::Matchers to work in my test/unit/..._test.rb tests has any one succeeded? should I migrate all those tests to the spec folder?
So, I'm using cucumber, Test::Unit, and before I started the project there were a bunch of spec tests.
When I was reading up on what testing framework to use for my unit tests, I found RSpec, and thought it was pretty cool... but as it turns out, I didn't actually use any Rspec until I found out about the should be_nil / be_whatever methods. I thought those were pretty cool.
I stuck with sticking tests in the test/(unit|functionals) folders, because it made the most sense (I thought having unit and functional tests in a "spec" folder was really weird and unconventional. I also began using shoulda, which enabled me to do should "test name" rather than it "should..." which I thought was more concise, and all around more intuitive.
But I recently started using cucumber for view testing, and... that resulted in tons of conflicting gem issues. It was a terrible hassle to get cucumber working with Factory girl, capybara, and the like.
I eventually had to migrate to bundler, because I could never get my environment working.
Anyway, after about a week of messing with the testing environment, cucumber works, functional tests work, and I feel like unit test WOULD work if I hadn't intially used .should be_valid / be_whateven methods.
Has anyone else gotten RSpec::Matchers to work in this scenario?
relevant part of GemFile:
group :test do
gem "cucumber", "~>0.10.3"
gem "cucumber-rails", "0.3.2"
gem "launchy"
gem "hpricot"
gem "gherkin", "~>2.4.0"
gem "capybara", "0.4.1.2"
gem "rspec", "~> 1.3.2"
gem "rack"
gem "rspec-rails", "~> 1.3.3"
gem "webrat", "0.7.0"
gem "database_cleaner"
gem "factory_girl", "2.1"
gem "shoulda", :require => nil
gem "shoulda-matchers", :git => "https://github.com/thoughtbot/shoulda-matchers"
gem "awesome_print"
gem "cobravsmongoose"
end
Here is the link to :
the rspec expectations page talking about integration with Test::Unit
My experience with testing with cucumber, rspec and test::unit leads me to believe that it is all about comfort as long as you are getting the coverage. I like rspec much more than test. If you are not really comfortable with test unit, definitely try rspec. I also know people (and am starting to lean this way myself) that just use cucumber and skip rspec all together (but this can get into a bit of a "religious" discussion).
When running test/unit using the rake test command from the terminal within a rails 3 project directory, the test result output is not coloured. Hence, it cannot be interpreted at a glance.
Is there a way of getting colourised output for the results, as you can get in rspec?
>rspec --colour
I discovered that redgreen was abandoned years ago, and found this solution which works well and requires no script hacking. The output, however, shows which test is being run in real time. So it is a lot longer than built in test output. It does have nice colors.
http://rubygems.org/gems/turn
In my Gemfile:
group :test do
gem 'turn'
end
Then run:
$ bundle install
$ rake test
The gem 'turn' works great. The caveat is that it doesn't seem to work with Mocha, due to monkey-patching issues. If you are using Mocha, you can use the redgreen gem. See instructions above in the approved answer for this question.
Yes, you can use the redgreen gem. Include it in your gemfile:
group :development, :test do
gem 'redgreen'
end
And that's all you need for ruby 1.8. If you're using 1.9, there's a workaround. add the test-unit gem:
group :development, :test do
gem 'redgreen'
gem 'test-unit', '1.2.3
end
It's not perfect with 1.9 - test-unit seems to run an empty test suite after every rake task or generator call, which is harmless but annoying.
I am working on Rails 5.1 / minitest and I was also searching for a solution to make the reporting color. None of these test::unit solutions are working, so I googled and saw this solution. Just add the following:
# Gemfile
gem 'minitest-reporters'
# test/test_helper.rb
require "minitest/reporters"
Minitest::Reporters.use!
Github: minitest-reporters