Joshua Muheim
2012-Jun-14 07:40 UTC
[rspec-users] response.should have_content("1 movie") does not seem to work for me
Hey everybody I have worked quite to near the end of The RSpec Book, but now I''m having some troubles. I''m trying to get the last few Cucumber steps to work, which are: Then /^Caddyshack should be in the Comedy genre$/ do visit genres_path click_link "Comedy" save_and_open_page response.should have_content("1 movie") response.should have_content("Caddyshack") end So far everything''s working, but the have_content("1 movie") doesn''t, although I have hard-coded the string into the view, and when displaying what Webrat sees using save_and_open_page, the string definitely is there! Name: Comedy Contains 1 movie Edit | Back This is what Cucumber tells me: Scenario: Create movie in genre # features/create_movie.feature:7 Given a genre named Comedy # features/step_definitions/genre_steps.rb:1 When I create a movie Caddyshack in the Comedy genre # features/step_definitions/movie_steps.rb:1 Then Caddyshack should be in the Comedy genre # features/step_definitions/movie_steps.rb:10 expected there to be content "1 movie" in "" (RSpec::Expectations::ExpectationNotMetError) ./features/step_definitions/movie_steps.rb:14:in `/^Caddyshack should be in the Comedy genre$/'' features/create_movie.feature:10:in `Then Caddyshack should be in the Comedy genre'' I''m sort of confused anyway, because in the RSpec book I''m told to use contains("1 movie"), but this method is not found! undefined method `contains'' for #<Cucumber::Rails::World:0x007fb114028010> (NoMethodError) After some searching on Google I got the hint to use should_contain("1 movie"), and this method seems to be available, but it doesn''t seem to work. Anyways, I''m a bit confused now, because should_contain() was claimed to be a Capybara thing, and not a Webrat thing, but I never read something about Capybara in the book, only about Webrat. So what am I using now, and why?? Is it because the book is a bit old already, and nowadays Rails uses Capybara by default? Because when removing gem "webrat" from my Gemfile, Cucumber doesn''t complain! Please also see my other post about this question (I''m sorry for having two posts, I didn''t realize they both would be about the same thing): http://www.ruby-forum.com/topic/4402795 Thanks a lot for help, Josh -- Posted via http://www.ruby-forum.com/.
Justin Ko
2012-Jun-15 15:13 UTC
[rspec-users] response.should have_content("1 movie") does not seem to work for me
On Jun 14, 2012, at 1:40 AM, Joshua Muheim wrote:> Hey everybody > > I have worked quite to near the end of The RSpec Book, but now I''m > having some troubles. > > I''m trying to get the last few Cucumber steps to work, which are: > > Then /^Caddyshack should be in the Comedy genre$/ do > visit genres_path > click_link "Comedy" > save_and_open_page > response.should have_content("1 movie") > response.should have_content("Caddyshack") > end > > So far everything''s working, but the have_content("1 movie") doesn''t, > although I have hard-coded the string into the view, and when displaying > what Webrat sees using save_and_open_page, the string definitely is > there! > > Name: Comedy > > Contains 1 movie > Edit | Back > > This is what Cucumber tells me: > > Scenario: Create movie in genre # > features/create_movie.feature:7 > Given a genre named Comedy # > features/step_definitions/genre_steps.rb:1 > When I create a movie Caddyshack in the Comedy genre # > features/step_definitions/movie_steps.rb:1 > Then Caddyshack should be in the Comedy genre # > features/step_definitions/movie_steps.rb:10 > expected there to be content "1 movie" in "" > (RSpec::Expectations::ExpectationNotMetError) > ./features/step_definitions/movie_steps.rb:14:in `/^Caddyshack > should be in the Comedy genre$/'' > features/create_movie.feature:10:in `Then Caddyshack should be in > the Comedy genre'' > > I''m sort of confused anyway, because in the RSpec book I''m told to use > contains("1 movie"), but this method is not found! > > undefined method `contains'' for > #<Cucumber::Rails::World:0x007fb114028010> (NoMethodError) > > After some searching on Google I got the hint to use should_contain("1 > movie"), and this method seems to be available, but it doesn''t seem to > work. Anyways, I''m a bit confused now, because should_contain() was > claimed to be a Capybara thing, and not a Webrat thing, but I never read > something about Capybara in the book, only about Webrat. So what am I > using now, and why?? Is it because the book is a bit old already, and > nowadays Rails uses Capybara by default? Because when removing > > gem "webrat" > > from my Gemfile, Cucumber doesn''t complain! > > Please also see my other post about this question (I''m sorry for having > two posts, I didn''t realize they both would be about the same thing): > > http://www.ruby-forum.com/topic/4402795 > > Thanks a lot for help, > Josh > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-usersFor Capybara, you want: page.should have_content For Webrat, I _think_ you want: response.should have_text
Joshua Muheim
2012-Jun-22 09:36 UTC
[rspec-users] response.should have_content("1 movie") does not seem to work for me
It seems I have to use page.should have_content("...") instead of response.should have_content("...") Maybe that''s because Capybara is the default engine now and not Webrat? -- Posted via http://www.ruby-forum.com/.
David Chelimsky
2012-Jun-22 13:18 UTC
[rspec-users] response.should have_content("1 movie") does not seem to work for me
On Fri, Jun 22, 2012 at 4:36 AM, Joshua Muheim <lists at ruby-forum.com> wrote:> It seems I have to use > > page.should have_content("...") > > instead of > > response.should have_content("...") > > Maybe that''s because Capybara is the default engine now and not Webrat?While Capybara seems to have become the de facto standard, there is no default (you have to configure one or the other in your app).> > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Possibly Parallel Threads
- RSpec with Rails 3.1rc4: spec test won't recognize <%= %> (should be simple)
- my icecast problem
- Cancan Rspec load_and_authorize_resource
- rspec-rails render_views doesn't render layouts? / how to check flash isn't rendered
- Oddness with fieldnames containing an underscore