≡

wincent.dev

  • Products
  • Blog
  • Wiki
  • Issues
You are viewing an historical archive of past issues. Please report new issues to the appropriate project issue tracker on GitHub.
Home » Issues » Feature request #1282

Feature request #1282: Create "loose" version of Webrat/Cucumber "should see" step

Kind feature request
Product wincent.dev
When 2009-04-20T06:31:26Z
Status closed
Reporter Greg Hurrell
Tags no tags

Description

Cucumber's "should see" step is a little too strict at times and makes it uncomfortable to write features.

For example, I might like to assert that I should see "Top tags" on the wiki index page. Saying 'I should see "Top tags"' will work only if those exact characters are literally on the page.

If I later turn "Top tags" into a hyperlink (ie. "Top tags" or Top <a href="/tags">tags</a>) then my Cucumber feature will break because the match is no longer exact.

This makes the features brittle and increases their maintenance cost.

So I'd like to introduce another step definition that will allow me to compare things "loosely", that is, make assertions about what I literally see on the page rather than on the character sequence I expect to find in the HTML source.

Basically, I'd like to take HTML source like Top <a href="/tags">tags</a>, strip out all tags to leave only "Top tags", and compare against the stripped version.

Comments

  1. Greg Hurrell 2009-04-20T06:32:36Z

    Status changed:

    • From: New
    • To: Open
  2. Greg Hurrell 2009-04-20T11:54:00Z
    diff --git a/features/step_definitions/webrat_steps.rb b/features/step_definitions/webrat_steps.rb
    index caf436d..6178549 100644
    --- a/features/step_definitions/webrat_steps.rb
    +++ b/features/step_definitions/webrat_steps.rb
    @@ -87,10 +87,18 @@ When /^I attach the file at "(.*)" to "(.*)" $/ do |path, field|
     end
     
     Then /^I should see "(.*)"$/ do |text|
    +  HTML::FullSanitizer.new.sanitize(response.body).should =~/#{text}/m
    +end
    +
    +Then /^The page source should match "(.*)"$/ do |text|
       response.body.should =~ /#{text}/m
     end
     
     Then /^I should not see "(.*)"$/ do |text|
    +  HTML::FullSanitizer.new.sanitize(response.body).should_not =~/#{text}/m
    +end
    +
    +Then /^The page source should not match "(.*)"$/ do |text|
       response.body.should_not =~ /#{text}/m
     end
  3. Greg Hurrell 2009-04-20T11:54:22Z

    Status changed:

    • From: Open
    • To: Closed
Add a comment

Comments are now closed for this issue.

  • contact
  • legal

Menu

  • Blog
  • Wiki
  • Issues
  • Snippets