Fernando Perez
2009-Jan-18 23:56 UTC
[rspec-users] [Cucumber, Webrat] I should see behaves strangely with html
Hi, In my tests, I check to see if a given html tag such as <title>...</title> 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? -- Posted via http://www.ruby-forum.com/.
Pau Cor
2009-Jan-19 04:18 UTC
[rspec-users] [Cucumber, Webrat] I should see behaves strangely with html
Can you please post the contents of your step definition? -- Posted via http://www.ruby-forum.com/.
Fernando Perez
2009-Jan-19 11:14 UTC
[rspec-users] [Cucumber, Webrat] I should see behaves strangely with html
Pau Cor 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 "<title>Hello world</title>, 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? -- Posted via http://www.ruby-forum.com/.
Pau Cor
2009-Jan-19 14:21 UTC
[rspec-users] [Cucumber, Webrat] I should see behaves strangely with html
Fernando Perez 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 > "<title>Hello world</title>, its definition is in webrat_steps.rbHere 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 -- Posted via http://www.ruby-forum.com/.
Zach Dennis
2009-Jan-19 18:17 UTC
[rspec-users] [Cucumber, Webrat] I should see behaves strangely with html
On Mon, Jan 19, 2009 at 9:21 AM, Pau Cor <lists at ruby-forum.com> wrote:> Fernando Perez 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 >> "<title>Hello world</title>, 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 > endIMO this should be the default,> > 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 > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com