[Cucumber, Webrat] I should see behaves strangely with html


#1

Hi,

In my tests, I check to see if a given html tag such as

... has the expected value, sometimes it works sometimes it tells me it couldn't find the string, although I see it printed out in the error screen.

I think it comes form the fact that double-quotes are escaped and
slashes too, and some other strange behavior with spaces and dashes, but
I am not sure about that.

How do you get round this problem?


#2

Can you please post the contents of your step definition?


#3

Pau C. wrote:

Can you please post the contents of your step definition?

I don’t have any step definition, I simply use: Then I should see
"Hello world, its definition is in webrat_steps.rb

However yesterday I looked in the code of a project (mephistoblog was
it?), and I noticed that they have: config.gem ‘nokogiri’ in
environement.rb. I don’t have it, is it compulsory for correctly parsing
the response body?


#4

Fernando P. wrote:

However yesterday I looked in the code of a project (mephistoblog was
it?), and I noticed that they have: config.gem ‘nokogiri’ in
environement.rb. I don’t have it, is it compulsory for correctly parsing
the response body?

I don’t have config.gem ‘nokogiri’ in environement.rb, but I do have the
gem installed.

I don’t have any step definition, I simply use: Then I should see
"Hello world, its definition is in webrat_steps.rb

Here is the step definition:
Then /^I should see “(.*)”$/ do |text|
response.body.should =~ /#{text}/m
end

That works pretty much the same way you would use it in RSpec. I don’t
see any webrat methods (please correct me if I am mistaken).

I think what might be tripping you up is that this step definition just
puts whatever is in quotes into a Regex. I personally think we should
avoid having a Regex in a step because most business users don’t
understand them. So I often change this matcher to be

Then /^I should see “(.*)”$/ do |text|
response.body.should =~ /#{Regexp.escape(text)}/m
end

I suggest you either try that step matcher, or you make sure your step
is properly escaping any special Regex characters. Perhaps this:
Then I should see “<title>Hello world</title>”

I believe that it prints out the regex used if response.body.should =~
/#{text}/m fails. If you still can’t get it to work, pasting the entire
output of you test here (maybe use Pastie.org)

Caveat: I am running version 0.1.13 so it is possible things have
changed.

HTH


#5

On Mon, Jan 19, 2009 at 9:21 AM, Pau C. removed_email_address@domain.invalid wrote:

I don’t have any step definition, I simply use: Then I should see
I think what might be tripping you up is that this step definition just
puts whatever is in quotes into a Regex. I personally think we should
avoid having a Regex in a step because most business users don’t
understand them. So I often change this matcher to be

Then /^I should see “(.*)”$/ do |text|
response.body.should =~ /#{Regexp.escape(text)}/m
end

IMO this should be the default,

changed.

HTH

Posted via http://www.ruby-forum.com/.


rspec-users mailing list
removed_email_address@domain.invalid
http://rubyforge.org/mailman/listinfo/rspec-users


Zach D.
http://www.continuousthinking.com
http://www.mutuallyhuman.com