aboutsummaryrefslogtreecommitdiffstats
path: root/features/step_definitions
diff options
context:
space:
mode:
Diffstat (limited to 'features/step_definitions')
-rw-r--r--features/step_definitions/authors_steps.rb7
-rw-r--r--features/step_definitions/category_steps.rb11
-rw-r--r--features/step_definitions/tags_steps.rb13
-rw-r--r--features/step_definitions/user_steps.rb42
-rw-r--r--features/step_definitions/web_steps.rb196
5 files changed, 269 insertions, 0 deletions
diff --git a/features/step_definitions/authors_steps.rb b/features/step_definitions/authors_steps.rb
new file mode 100644
index 0000000..eaa5f32
--- /dev/null
+++ b/features/step_definitions/authors_steps.rb
@@ -0,0 +1,7 @@
+Then /^there should be (\d+) blog posts?$/ do |num|
+ ::Refinery::BlogPost.all.size == num
+end
+
+Then /^the blog post should belong to me$/ do
+ ::Refinery::BlogPost.first.author.login == ::Refinery::User.last.login
+end \ No newline at end of file
diff --git a/features/step_definitions/category_steps.rb b/features/step_definitions/category_steps.rb
new file mode 100644
index 0000000..3c197e2
--- /dev/null
+++ b/features/step_definitions/category_steps.rb
@@ -0,0 +1,11 @@
+Given /^there is a category titled "([^"]*)"$/ do |title|
+ @category = Factory.create(:blog_category, :title => title)
+end
+
+Then /^the blog post should have ([\d]*) categor[yies]{1,3}$/ do |num_category|
+ ::Refinery::BlogPost.last.categories.count.should == num_category.to_i
+end
+
+Then /^the blog post should have the category "([^"]*)"$/ do |category|
+ ::Refinery::BlogPost.last.categories.first.title.should == category
+end
diff --git a/features/step_definitions/tags_steps.rb b/features/step_definitions/tags_steps.rb
new file mode 100644
index 0000000..d16f758
--- /dev/null
+++ b/features/step_definitions/tags_steps.rb
@@ -0,0 +1,13 @@
+Given /^there is a blog post titled "([^"]*)" and tagged "([^"]*)"$/ do |title, tag_name|
+ @blog_post = Factory.create(:blog_post, :title => title, :tag_list => tag_name)
+end
+
+When /^I visit the tagged posts page for "([^"]*)"$/ do |tag_name|
+ @blog_post ||= Factory.create(:blog_post, :tag_list => tag_name)
+ tag = ::Refinery::BlogPost.tag_counts_on(:tags).first
+ visit tagged_posts_path(tag.id, tag_name.parameterize)
+end
+
+Then /^the blog post should have the tags "([^"]*)"$/ do |tag_list|
+ ::Refinery::BlogPost.last.tag_list == tag_list.split(', ')
+end
diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb
new file mode 100644
index 0000000..002fa7d
--- /dev/null
+++ b/features/step_definitions/user_steps.rb
@@ -0,0 +1,42 @@
+def login(options = {})
+ options = {:user => @refinery_user}.merge(options)
+ visit new_refinery_user_session_path
+ fill_in("refinery_user_login", :with => options[:user].email)
+ fill_in("refinery_user_password", :with => 'greenandjuicy')
+ click_button("submit_button")
+end
+
+Given /^I am a logged in refinery user$/i do
+ @refinery_user ||= Factory(:refinery_user)
+ login(:user => @refinery_user)
+end
+
+Given /^I am a logged in refinery translator$/i do
+ @refinery_translator ||= Factory(:refinery_translator)
+ login(:user => @refinery_translator)
+end
+
+Given /^I am a logged in customer$/i do
+ @user ||= Factory(:user)
+ login(:user => @user)
+end
+
+Given /^A Refinery user exists$/i do
+ @refinery_user ||= Factory(:refinery_user)
+end
+
+Given /^I have a user named "(.*)"$/ do |name|
+ @user = Factory(:user, :username => name)
+end
+
+Given /^I have a refinery user named "(.*)"$/i do |name|
+ @refinery_user = Factory(:refinery_user, :username => name)
+end
+
+Given /^I have no users$/ do
+ ::Refinery::User.delete_all
+end
+
+Then /^I should have ([0-9]+) users?$/ do |count|
+ ::Refinery::User.count.should == count.to_i
+end
diff --git a/features/step_definitions/web_steps.rb b/features/step_definitions/web_steps.rb
new file mode 100644
index 0000000..22abbf6
--- /dev/null
+++ b/features/step_definitions/web_steps.rb
@@ -0,0 +1,196 @@
+# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
+# It is recommended to regenerate this file in the future when you upgrade to a
+# newer version of cucumber-rails. Consider adding your own code to a new file
+# instead of editing this one. Cucumber will automatically load all features/**/*.rb
+# files.
+
+require 'uri'
+require 'cgi'
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "selectors"))
+
+module WithinHelpers
+ def with_scope(locator)
+ locator ? within(*selector_for(locator)) { yield } : yield
+ end
+end
+World(WithinHelpers)
+
+# Single-line step scoper
+When /^(.*) within (.*[^:])$/ do |step, parent|
+ with_scope(parent) { When step }
+end
+
+# Multi-line step scoper
+When /^(.*) within (.*[^:]):$/ do |step, parent, table_or_string|
+ with_scope(parent) { When "#{step}:", table_or_string }
+end
+
+Given /^(?:|I )am on (.+)$/ do |page_name|
+ visit path_to(page_name)
+end
+
+When /^(?:|I )go to (.+)$/ do |page_name|
+ visit path_to(page_name)
+end
+
+When /^(?:|I )press "([^"]*)"$/ do |button|
+ click_button(button)
+end
+
+When /^(?:|I )follow "([^"]*)"$/ do |link|
+ click_link(link)
+end
+
+When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
+ fill_in(field, :with => value)
+end
+
+When /^(?:|I )fill in "([^"]*)" for "([^"]*)"$/ do |value, field|
+ fill_in(field, :with => value)
+end
+
+# Use this to fill in an entire form with data from a table. Example:
+#
+# When I fill in the following:
+# | Account Number | 5002 |
+# | Expiry date | 2009-11-01 |
+# | Note | Nice guy |
+# | Wants Email? | |
+#
+# TODO: Add support for checkbox, select og option
+# based on naming conventions.
+#
+When /^(?:|I )fill in the following:$/ do |fields|
+ fields.rows_hash.each do |name, value|
+ When %{I fill in "#{name}" with "#{value}"}
+ end
+end
+
+When /^(?:|I )select "([^"]*)" from "([^"]*)"$/ do |value, field|
+ select(value, :from => field)
+end
+
+When /^(?:|I )check "([^"]*)"$/ do |field|
+ check(field)
+end
+
+When /^(?:|I )uncheck "([^"]*)"$/ do |field|
+ uncheck(field)
+end
+
+When /^(?:|I )choose "([^"]*)"$/ do |field|
+ choose(field)
+end
+
+When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"$/ do |path, field|
+ attach_file(field, File.expand_path(path))
+end
+
+Then /^(?:|I )should see "([^"]*)"$/ do |text|
+ if page.respond_to? :should
+ page.should have_content(text)
+ else
+ assert page.has_content?(text)
+ end
+end
+
+Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
+ regexp = Regexp.new(regexp)
+
+ if page.respond_to? :should
+ page.should have_xpath('//*', :text => regexp)
+ else
+ assert page.has_xpath?('//*', :text => regexp)
+ end
+end
+
+Then /^(?:|I )should not see "([^"]*)"$/ do |text|
+ if page.respond_to? :should
+ page.should have_no_content(text)
+ else
+ assert page.has_no_content?(text)
+ end
+end
+
+Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
+ regexp = Regexp.new(regexp)
+
+ if page.respond_to? :should
+ page.should have_no_xpath('//*', :text => regexp)
+ else
+ assert page.has_no_xpath?('//*', :text => regexp)
+ end
+end
+
+Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value|
+ with_scope(parent) do
+ field = find_field(field)
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
+ if field_value.respond_to? :should
+ field_value.should =~ /#{value}/
+ else
+ assert_match(/#{value}/, field_value)
+ end
+ end
+end
+
+Then /^the "([^"]*)" field(?: within (.*))? should not contain "([^"]*)"$/ do |field, parent, value|
+ with_scope(parent) do
+ field = find_field(field)
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
+ if field_value.respond_to? :should_not
+ field_value.should_not =~ /#{value}/
+ else
+ assert_no_match(/#{value}/, field_value)
+ end
+ end
+end
+
+Then /^the "([^"]*)" checkbox(?: within (.*))? should be checked$/ do |label, parent|
+ with_scope(parent) do
+ field_checked = find_field(label)['checked']
+ if field_checked.respond_to? :should
+ field_checked.should be_true
+ else
+ assert field_checked
+ end
+ end
+end
+
+Then /^the "([^"]*)" checkbox(?: within (.*))? should not be checked$/ do |label, parent|
+ with_scope(parent) do
+ field_checked = find_field(label)['checked']
+ if field_checked.respond_to? :should
+ field_checked.should be_false
+ else
+ assert !field_checked
+ end
+ end
+end
+
+Then /^(?:|I )should be on (.+)$/ do |page_name|
+ current_path = URI.parse(current_url).path
+ if current_path.respond_to? :should
+ current_path.should == path_to(page_name)
+ else
+ assert_equal path_to(page_name), current_path
+ end
+end
+
+Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
+ query = URI.parse(current_url).query
+ actual_params = query ? CGI.parse(query) : {}
+ expected_params = {}
+ expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
+
+ if actual_params.respond_to? :should
+ actual_params.should == expected_params
+ else
+ assert_equal expected_params, actual_params
+ end
+end
+
+Then /^show me the page$/ do
+ save_and_open_page
+end