aboutsummaryrefslogtreecommitdiffstats
path: root/features/support
diff options
context:
space:
mode:
authorJamie Winsor <jamie@enmasse.com>2011-08-01 11:27:28 -0700
committerJamie Winsor <jamie@enmasse.com>2011-08-03 18:01:32 -0700
commit21b19db5a30fcb6db83f4ac9302cc94c6320a0db (patch)
tree62a3b89d0f4c9b239bfd76ec77cfc3269ac041ef /features/support
parent3454a9c3007a4bfd10ccd0ff39dc594ebb2a0184 (diff)
downloadrefinerycms-blog-21b19db5a30fcb6db83f4ac9302cc94c6320a0db.tar.gz
refinerycms-blog-21b19db5a30fcb6db83f4ac9302cc94c6320a0db.tar.bz2
refinerycms-blog-21b19db5a30fcb6db83f4ac9302cc94c6320a0db.zip
refactor engine testing scenario
Engine is now tested standalone by leveraging a dummy rails app Enable Guard for speedy testing Move factories to the more standard location `spec/factories/*` Update README with a Testing section Rename migrations to contain datetimestamps for their version to fix migration order issues when migrating the dummy application
Diffstat (limited to 'features/support')
-rw-r--r--features/support/env.rb50
-rw-r--r--features/support/paths.rb34
-rw-r--r--features/support/selectors.rb39
-rw-r--r--features/support/step_definitions/authors_steps.rb7
-rw-r--r--features/support/step_definitions/category_steps.rb11
-rw-r--r--features/support/step_definitions/tags_steps.rb13
6 files changed, 103 insertions, 51 deletions
diff --git a/features/support/env.rb b/features/support/env.rb
new file mode 100644
index 0000000..a84d601
--- /dev/null
+++ b/features/support/env.rb
@@ -0,0 +1,50 @@
+require 'rubygems'
+require 'bundler/setup'
+require 'spork'
+
+Spork.prefork do
+ require 'cucumber/rails'
+ require 'capybara/rails'
+ require 'capybara/cucumber'
+ require 'capybara/session'
+
+ require 'factory_girl'
+ require 'database_cleaner'
+ require 'database_cleaner/cucumber'
+
+ Dir[File.expand_path("../../../spec/factories/*.rb", __FILE__)].each {|f| require f}
+
+ include ::Devise::Controllers::UrlHelpers
+
+ # Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
+ # order to ease the transition to Capybara we set the default here. If you'd
+ # prefer to use XPath just remove this line and adjust any selectors in your
+ # steps to use the XPath syntax.
+ Capybara.default_selector = :css
+
+ # By default, any exception happening in your Rails application will bubble up
+ # to Cucumber so that your scenario will fail. This is a different from how
+ # your application behaves in the production environment, where an error page will
+ # be rendered instead.
+ #
+ # Sometimes we want to override this default behaviour and allow Rails to rescue
+ # exceptions and display an error page (just like when the app is running in production).
+ # Typical scenarios where you want to do this is when you test your error pages.
+ # There are two ways to allow Rails to rescue exceptions:
+ #
+ # 1) Tag your scenario (or feature) with @allow-rescue
+ #
+ # 2) Set the value below to true. Beware that doing this globally is not
+ # recommended as it will mask a lot of errors for you!
+ #
+ ActionController::Base.allow_rescue = false
+
+ DatabaseCleaner.strategy = :truncation
+
+ Before { DatabaseCleaner.start }
+ After { DatabaseCleaner.clean }
+end
+
+Spork.each_run do
+ # This code will be run each time you run your specs.
+end
diff --git a/features/support/paths.rb b/features/support/paths.rb
index 1fdf9f8..f69b8fe 100644
--- a/features/support/paths.rb
+++ b/features/support/paths.rb
@@ -1,24 +1,18 @@
-module NavigationHelpers
- module Refinery
- module Blog
- def path_to(page_name)
- case page_name
- when /the list of blog posts/
- refinery_admin_blog_posts_path
- when /the new blog posts? form/
- new_refinery_admin_blog_post_path
- else
- begin
- if page_name =~ /the blog post titled "?([^\"]*)"?/ and (page = BlogPost.find_by_title($1)).present?
- self.url_for(page.url)
- else
- nil
- end
- rescue
- nil
- end
- end
+def path_to(page_name)
+ case page_name
+ when /the list of blog posts/
+ refinery_admin_blog_posts_path
+ when /the new blog posts? form/
+ new_refinery_admin_blog_post_path
+ else
+ begin
+ if page_name =~ /the blog post titled "?([^\"]*)"?/ and (page = BlogPost.find_by_title($1)).present?
+ self.url_for(page.url)
+ else
+ nil
end
+ rescue
+ nil
end
end
end
diff --git a/features/support/selectors.rb b/features/support/selectors.rb
new file mode 100644
index 0000000..44e34a4
--- /dev/null
+++ b/features/support/selectors.rb
@@ -0,0 +1,39 @@
+module HtmlSelectorsHelpers
+ # Maps a name to a selector. Used primarily by the
+ #
+ # When /^(.+) within (.+)$/ do |step, scope|
+ #
+ # step definitions in web_steps.rb
+ #
+ def selector_for(locator)
+ case locator
+
+ when "the page"
+ "html > body"
+
+ # Add more mappings here.
+ # Here is an example that pulls values out of the Regexp:
+ #
+ # when /^the (notice|error|info) flash$/
+ # ".flash.#{$1}"
+
+ # You can also return an array to use a different selector
+ # type, like:
+ #
+ # when /the header/
+ # [:xpath, "//header"]
+
+ # This allows you to provide a quoted selector as the scope
+ # for "within" steps as was previously the default for the
+ # web steps:
+ when /^"(.+)"$/
+ $1
+
+ else
+ raise "Can't find mapping from \"#{locator}\" to a selector.\n" +
+ "Now, go and add a mapping in #{__FILE__}"
+ end
+ end
+end
+
+World(HtmlSelectorsHelpers)
diff --git a/features/support/step_definitions/authors_steps.rb b/features/support/step_definitions/authors_steps.rb
deleted file mode 100644
index eaa5f32..0000000
--- a/features/support/step_definitions/authors_steps.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-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/support/step_definitions/category_steps.rb b/features/support/step_definitions/category_steps.rb
deleted file mode 100644
index 3c197e2..0000000
--- a/features/support/step_definitions/category_steps.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-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/support/step_definitions/tags_steps.rb b/features/support/step_definitions/tags_steps.rb
deleted file mode 100644
index d16f758..0000000
--- a/features/support/step_definitions/tags_steps.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-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