Navigation Menu

Skip to content

Commit

Permalink
Add scenario for query matching
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed May 4, 2010
1 parent 685aa45 commit d7d64ca
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
29 changes: 27 additions & 2 deletions features/rails3.feature
Expand Up @@ -44,19 +44,44 @@ Feature: Rails 3
And I successfully run "rails generate cucumber:skeleton --capybara"
And I successfully run "rails generate cucumber:feature post title:string body:text published:boolean"
And I successfully run "rails generate scaffold post title:string body:text published:boolean"
And I successfully run "rails generate scaffold cukes name:string"
And I append to "Gemfile" with:
"""
gem 'capybara', '0.3.7'
gem 'webrat', '0.7.0'
gem 'cucumber', '0.7.1'
"""
And I write to "app/controllers/cukes_controller.rb" with:
"""
class CukesController < ApplicationController
def index
redirect_to cuke_path(10, :overwrite_params => {:name => 'cucumber', :what => 'vegetable'})
end
def show
render :text => "Cuke #{params[:id]}"
end
end
"""
And I write to "features/tests.feature" with:
"""
Feature: Tests
Scenario: Tests
When I go to the cukes page
Then I should have the following query string:
|name|cucumber|
|what|vegetable|
|controller|cukes|
|action|index|
And I should see "Cuke 10"
"""
And I successfully run "bundle install"
And I successfully run "rake db:migrate"
And I successfully run "rake cucumber"
Then it should pass with:
"""
2 scenarios (2 passed)
11 steps (11 passed)
3 scenarios (3 passed)
14 steps (14 passed)
"""

6 changes: 4 additions & 2 deletions templates/skeleton/step_definitions/capybara_steps.rb.erb
@@ -1,6 +1,7 @@
<%= embed_file('support/edit_warning.txt') %>

require 'uri'
require 'cgi'
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))

module WithinHelpers
Expand Down Expand Up @@ -194,8 +195,9 @@ Then /^(?:|I )should be on (.+)$/ do |page_name|
end

Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
actual_params = CGI.parse(URI.parse(current_url).query)
expected_params = Hash[expected_pairs.rows_hash.map{|k,v| [k,[v]]}]
query = URI.parse(current_url).query
actual_params = query ? CGI.parse(query) : {}
expected_params = Hash[expected_pairs.rows_hash.map{|k,v| [k,v.split(',')]}]

if actual_params.respond_to? :should
actual_params.should == expected_params
Expand Down
6 changes: 4 additions & 2 deletions templates/skeleton/step_definitions/webrat_steps.rb.erb
@@ -1,6 +1,7 @@
<%= embed_file('support/edit_warning.txt') %>

require 'uri'
require 'cgi'
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))

# Commonly used webrat steps
Expand Down Expand Up @@ -258,8 +259,9 @@ Then /^(?:|I )should be on (.+)$/ do |page_name|
end

Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
actual_params = CGI.parse(URI.parse(current_url).query)
expected_params = Hash[expected_pairs.rows_hash.map{|k,v| [k,[v]]}]
query = URI.parse(current_url).query
actual_params = query ? CGI.parse(query) : {}
expected_params = Hash[expected_pairs.rows_hash.map{|k,v| [k,v.split(',')]}]

if actual_params.respond_to? :should
actual_params.should == expected_params
Expand Down

0 comments on commit d7d64ca

Please sign in to comment.