Skip to content

Commit

Permalink
[SEARCH] Refactored the search steps to a higher-level nested step "I…
Browse files Browse the repository at this point in the history
… search for ..."

Instead of repeating the low-level steps:

    When I go to the homepage
    And I fill in "query" with "<query>"
    And I press "Search"

over and over in our scenarios, we will abstract these steps to a single step:

    When I search for "<query>"

The obvious benefit is less code duplication and more readable steps.
  • Loading branch information
karmi committed Aug 29, 2012
1 parent da0981a commit b203bfc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 27 deletions.
28 changes: 7 additions & 21 deletions features/search.feature
Expand Up @@ -11,9 +11,7 @@ Feature: Search
| name: LDAP | mail stuff |
| name: twitter | social junk |
| name: beer_laser | amazing beer |
When I go to the homepage
And I fill in "query" with "<query>"
And I press "Search"
When I search for "<query>"
Then I should see "<result>"

Examples:
Expand All @@ -28,38 +26,30 @@ Feature: Search
Given the following version exists:
| rubygem | description |
| name: foos-paperclip | paperclip |
When I go to the homepage
And I fill in "query" with "paperclip"
And I press "Search"
When I search for "paperclip"
Then I should not see "Exact match"
But I should see "foos-paperclip"

Scenario: The only pushed version of a gem is yanked
Given the following version exists:
| rubygem | number | indexed |
| name: RGem | 1.0.0 | false |
When I go to the homepage
And I fill in "query" with "RGem"
And I press "Search"
When I search for "RGem"
Then I should not see "RGem (1.0.0)"

Scenario: The most recent version of a gem is yanked
Given the following versions exist:
| rubygem | number | indexed |
| name: RGem | 1.2.1 | true |
| name: RGem | 1.2.2 | false |
When I go to the homepage
And I fill in "query" with "RGem"
And I press "Search"
When I search for "RGem"
And I should see "RGem (1.2.1)"
And I should not see "RGem (1.2.2)"

Scenario: The most downloaded gem is listed first
Given a rubygem "Cereal-Bowl" exists with version "0.0.1" and 500 downloads
And a rubygem "Cereal" exists with version "0.0.9" and 5 downloads
When I go to the homepage
And I fill in "query" with "cereal"
And I press "Search"
When I search for "cereal"
Then I should see these search results:
| Cereal-Bowl (0.0.1) |
| Cereal (0.0.9) |
Expand All @@ -68,17 +58,13 @@ Feature: Search
Given a rubygem "Straight-F" exists with version "0.0.1" and 10 downloads
And a rubygem "Straight-B" exists with version "0.0.1" and 0 downloads
And a rubygem "Straight-A" exists with version "0.0.1" and 0 downloads
When I go to the homepage
And I fill in "query" with "straight"
And I press "Search"
When I search for "straight"
Then I should see these search results:
| Straight-F (0.0.1) |
| Straight-A (0.0.1) |
| Straight-B (0.0.1) |

Scenario: The user enters a search query with incorrect syntax
When I go to the homepage
And I fill in "query" with "bang!"
And I press "Search"
When I search for "bang!"
Then I should not see /Displaying.*Rubygem/
But I should see "Sorry, your query is incorrect."
8 changes: 2 additions & 6 deletions features/search_advanced.feature
Expand Up @@ -11,9 +11,7 @@ Feature: Search Advanced
| name: sinatra | 0.0.1 | Sinatra is a DSL ... | |
| name: vegas | 0.0.1 | executable versions ... Sinatra/Rack apps | |
| name: capybara | 0.0.1 | | ... testing Sinatra ... |
When I go to the homepage
And I fill in "query" with "sinatra"
And I press "Search"
When I search for "sinatra"
Then I should see these search results:
| capybara (0.0.1) |
| sinatra (0.0.1) |
Expand All @@ -25,9 +23,7 @@ Scenario: Searching in authors
| sinatra | 0.0.1 | Blake Mizerany, Ryan Tomayko | 500 |
| beefcake | 0.0.1 | Blake Mizerany | 50 |
| vegas | 0.0.1 | Aaron Quint | 5 |
When I go to the homepage
And I fill in "query" with "author:blake"
And I press "Search"
When I search for "author:blake"
Then I should see these search results:
| sinatra (0.0.1) |
| beefcake (0.0.1) |
8 changes: 8 additions & 0 deletions features/step_definitions/search_steps.rb
@@ -1,3 +1,11 @@
When /^I search for "([^"]*)"$/ do |query|
steps %{
When I go to the homepage
And I fill in "query" with "#{query}"
And I press "Search"
}
end

Then /^I should see these search results:$/ do |expected_table|
# TODO: Make less brittle with an explicit CSS class in the view
results = page.all(".gems:last-child li a strong").collect(&:text)
Expand Down

0 comments on commit b203bfc

Please sign in to comment.