Permalink
Browse files

Test framework.

  • Loading branch information...
1 parent 24d8652 commit c3553c0d2194d8d53f058b2b4c5a6771109c13d7 @jfirebaugh committed Oct 17, 2010
Showing with 65 additions and 0 deletions.
  1. +5 −0 Rakefile
  2. +26 −0 features/step_definitions/web_steps.rb
  3. +16 −0 features/support/env.rb
  4. +18 −0 features/support/selectors.rb
View
@@ -1,2 +1,7 @@
require 'bundler'
+require 'cucumber/rake/task'
+
Bundler::GemHelper.install_tasks
+Cucumber::Rake::Task.new
+
+task :default => :cucumber
@@ -0,0 +1,26 @@
+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
+
+When /^I visit the (.+) page$/ do |page|
+ visit("/#{page}.html")
+end
+
+Then /^I should see "([^"]+)"$/ do |text|
+ page.should have_content(text)
+end
View
@@ -0,0 +1,16 @@
+require 'bundler'
+Bundler.require
+
+require 'capybara/cucumber'
+require 'bermuda/cucumber'
+
+require 'rack/builder'
+require 'rack/file'
+require 'rack/directory'
+
+Capybara.configure do |config|
+ config.default_driver = :selenium
+ config.app = Rack::Builder.app do
+ run Rack::Directory.new "public"
+ end
+end
@@ -0,0 +1,18 @@
+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
+
+ 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)

0 comments on commit c3553c0

Please sign in to comment.