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:
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.
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
have_text is not supported in rspec-2.
For JSON, I like to deserialize the output and match against the decoded
JSON:
RSpec::Matchers.define :be_json do |expected_json|
match do |response|
json = ActiveSupport::JSON::decode(response.body)
json.should == expected_json
end
end
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: