turkan
2010-Sep-30 20:50 UTC
[rspec-users] response.should have_text leads to undefined method `has_text?''
One of my controllers directly renders some JSON output that I would like to test with RSpec. For that I use ''response.should have_text("foobar")'' in my spec file, but that leads to a Failure/Error: response.should have_text("enim") undefined method `has_text?'' for #<ActionController::TestResponse: 0xb6736944> I read here somewhere that webrat should be in the Gemfile, but that also did not solve the problem. Best regards, Kai
Kai Schlamp
2010-Oct-02 19:27 UTC
[rspec-users] response.should have_text leads to undefined method `has_text?''
A big hello. I would like to test a controller that directly renders some JSON output (by using "render :json => @entity_names"). For that task I tried in my spec file "response.should have_text(''["enim", "enita"]'')". Unfortunately I always get that error: Failure/Error: response.should have_text(''["enim", "enita"]'') undefined method `has_text?'' for " ":String (Also a "response.body.should have_text(''["enim", "enita"]'')as someone suggested on Stackoverflow did not solve the problem.) Do I miss some gem that provides that method? Here my Gemfile: source ''http://rubygems.org'' gem ''rails'', ''>= 3.0.0'' gem ''mysql2'' gem ''mongrel'' gem ''devise'' gem ''will_paginate'', :git => ''git://github.com/mislav/will_paginate.git'', :branch => ''rails3'' gem ''thinking-sphinx'', :git => ''git://github.com/freelancing-god/thinking-sphinx.git'', :branch => ''rails3'', :require => ''thinking_sphinx'' group :test, :development do gem ''rspec-rails'', ''>= 2.0.0.beta.19'' gem ''steak'', :git => ''git://github.com/cavalle/steak.git'' gem ''webrat'' gem ''capybara'' gem ''capybara-envjs'' gem ''shoulda'' gem ''launchy'' gem ''autotest'' gem ''autotest-rails'' gem ''test_notifier'' gem ''rails3-generators'' gem ''factory_girl_rails'' gem ''populator'' gem ''faker'' gem ''random_data'' gem ''database_cleaner'', :git => ''git://github.com/bmabey/database_cleaner.git'' gem ''delorean'' end Best regards, Kai -- GMX DSL Doppel-Flat ab 19,99 €/mtl.! Jetzt auch mit gratis Notebook-Flat! http://portal.gmx.net/de/go/dsl
David Chelimsky
2010-Oct-02 20:04 UTC
[rspec-users] response.should have_text leads to undefined method `has_text?''
On Oct 2, 2010, at 2:27 PM, Kai Schlamp wrote:> A big hello. > > I would like to test a controller that directly renders some JSON output (by using "render :json => @entity_names"). For that task I tried in my spec file "response.should have_text(''["enim", "enita"]'')". Unfortunately I always get that error: > Failure/Error: response.should have_text(''["enim", "enita"]'') > undefined method `has_text?'' for " ":Stringhave_text is not supported in rspec-2. For JSON, I like to deserialize the output and match against the decoded JSON: json = ActiveSupport::JSON::decode(response.body) json.should eq(%w[enim enita]) Then you could wrap that in a matcher: RSpec::Matchers.define :be_json do |expected_json| match do |response| json = ActiveSupport::JSON::decode(response.body) json.should == expected_json end end response.should be_json(%w[enim enita]) HTH, David> > (Also a "response.body.should have_text(''["enim", "enita"]'')as someone suggested on Stackoverflow did not solve the problem.) > > Do I miss some gem that provides that method? Here my Gemfile: > > source ''http://rubygems.org'' > > gem ''rails'', ''>= 3.0.0'' > gem ''mysql2'' > gem ''mongrel'' > gem ''devise'' > gem ''will_paginate'', :git => ''git://github.com/mislav/will_paginate.git'', :branch => ''rails3'' > gem ''thinking-sphinx'', :git => ''git://github.com/freelancing-god/thinking-sphinx.git'', :branch => ''rails3'', :require => ''thinking_sphinx'' > > group :test, :development do > gem ''rspec-rails'', ''>= 2.0.0.beta.19'' > gem ''steak'', :git => ''git://github.com/cavalle/steak.git'' > gem ''webrat'' > gem ''capybara'' > gem ''capybara-envjs'' > gem ''shoulda'' > gem ''launchy'' > gem ''autotest'' > gem ''autotest-rails'' > gem ''test_notifier'' > gem ''rails3-generators'' > gem ''factory_girl_rails'' > gem ''populator'' > gem ''faker'' > gem ''random_data'' > gem ''database_cleaner'', :git => ''git://github.com/bmabey/database_cleaner.git'' > gem ''delorean'' > end > > Best regards, > Kai > -- > GMX DSL Doppel-Flat ab 19,99 €/mtl.! Jetzt auch mit > gratis Notebook-Flat! http://portal.gmx.net/de/go/dsl > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
David Chelimsky
2010-Oct-05 12:47 UTC
[rspec-users] response.should have_text leads to undefined method `has_text?''
On Sep 30, 2010, at 3:50 PM, turkan wrote:> One of my controllers directly renders some JSON output that I would > like to test with RSpec. For that I use ''response.should > have_text("foobar")'' in my spec file, but that leads to a > > Failure/Error: response.should have_text("enim") > undefined method `has_text?'' for #<ActionController::TestResponse: > 0xb6736944> > > I read here somewhere that webrat should be in the Gemfile, but that > also did not solve the problem.The webrat matcher is contain: response.should contain("enim") HTH, David
Kurt
2011-Jan-13 19:04 UTC
[rspec-users] response.should have_text leads to undefined method `has_text?''
Where are the changes to RSpec2 documented? I haven''t been able to find a list of changes that would include something like this removal of have_text. Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110113/540e854b/attachment.html>
David Chelimsky
2011-Jan-13 19:19 UTC
[rspec-users] response.should have_text leads to undefined method `has_text?''
On Jan 13, 2011, at 1:04 PM, Kurt wrote:> Where are the changes to RSpec2 documented? I haven''t been able to find a list of changes that would include something like this removal of have_text. Thanks.have_text being pulled is not documented yet. Oversight on my part. Just added an issue for it: https://github.com/rspec/rspec-rails/issues/issue/305 per other email on this list: official docs are at http://relishapp.com/rspec. Info about contributing to the docs can be found there and at http://blog.davidchelimsky.net/2010/12/23/rspec-2-documentation-2/.