Browse files

Revert "Cleaning"

This reverts commit e51b468.
  • Loading branch information...
1 parent 457430a commit 79a3385694267fcec59b14f517d85861f0cc2436 @josephwilk committed Dec 2, 2011
View
27 wantworkshop_demo/features/step_definitions/want_steps.rb
@@ -0,0 +1,27 @@
+Given /^I have expressed a want for "([^\"]*)" Workshop$/ do |workshop_name|
+ want_automator.submit_a_want(:name => workshop_name)
+end
+
+When /^I express a want for a Workshop$/ do
+ want_automator.submit_a_want
+end
+
+When /^I express a want for a Workshop with an invalid email$/ do
+ want_automator.submit_a_want(:email => 'blah')
+end
+
+When /^I express another want for the Workshop$/ do
+ want_automator.submit_a_want(:email => want_automator.previous_wants_email)
+end
+
+Then /^I should be marked as tracking the Workshop$/ do
+ want_automator.should_be_tracking_the_workshop
+end
+
+Then /^I should see an error about my want saying my email is invalid$/ do
+ want_automator.should have_error("Email is invalid")
+end
+
+Then /^I should see an error about my want saying I'm already registered for this workshop$/ do
+ want_automator.should have_error("Email has already been registered")
+end
View
3 wantworkshop_demo/features/step_definitions/workshop_steps.rb
@@ -0,0 +1,3 @@
+Given /^a (\w+) "([^\"]*)"$/ do |thing, name|
+ Factory(thing.downcase.to_sym, :name => name)
+end
View
33 wantworkshop_demo/features/support/env.rb
@@ -0,0 +1,33 @@
+ENV['RAILS_ENV'] = RAILS_ENV = 'test'
+
+require 'cucumber/rails'
+require File.dirname(__FILE__) + "/factories"
+
+Capybara.default_selector = :css
+ActionController::Base.allow_rescue = false
+
+WantWorkshop::Factories.init
+
+module DSL
+end
+
+begin
+ DatabaseCleaner.strategy = :transaction
+rescue NameError
+ raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
+end
+
+if ENV['FULL_STACK']
+ puts "[INFO] FULL_STACK=true Full Stack testing"
+else
+ puts "[INFO] FULL_STACK=false Testing Under the GUI"
+end
+
+def workshop_under_discussion(name = nil)
+ if name
+ workshop = Workshop.find_by_name(name)
+ else
+ raise Exception.new("I don't know which workshop you mean. You have more than one!") if Workshop.count > 1
+ Workshop.first
+ end
+end
View
30 wantworkshop_demo/features/support/factories.rb
@@ -0,0 +1,30 @@
+require 'factory_girl'
+
+module WantWorkshop
+ module Factories
+ class << self
+ def init
+ init_sequences
+ init_definitions
+ end
+
+ def init_sequences
+ Factory.sequence :email_address do |n|
+ "test-user-#{n}@wantworkshop.com"
+ end
+ end
+
+ def init_definitions
+ Factory.define :want do |want|
+ want.email { Factory.next(:email_address) }
+ want.association :workshop
+ end
+
+ Factory.define :workshop do |workshop|
+ workshop.name 'Test workshop'
+ end
+
+ end
+ end
+ end
+end
View
3 wantworkshop_demo/features/support/transforms.rb
@@ -0,0 +1,3 @@
+WANT = Transform /(\d+)/ do |number|
+ number.to_i
+end
View
70 wantworkshop_demo/features/support/want_support.rb
@@ -0,0 +1,70 @@
+require 'capybara/dsl'
+require 'rspec/core'
+require 'capybara/rspec/matchers'
+
+module DSL::Want
+ class WantBase
+ def previous_wants_email
+ lead = Want.last
+ raise Exception.new("No Wants!") unless lead
+ lead.email
+ end
+ end
+
+ class WantAutomator < WantBase
+ include Capybara::RSpecMatchers
+ include Capybara::DSL
+
+ def initialize
+ end
+
+ def submit_a_want(params={})
+ workshop = workshop_under_discussion(params[:name])
+ visit "/workshops/#{workshop.id}"
+
+ fill_in 'email-input', :with => params[:email] || Factory.next(:email_address)
+ click_button 'want'
+ end
+
+ def should_be_tracking_the_workshop
+ page.should have_content "Thanks"
+ end
+
+ def has_error?(message)
+ page.should have_content message
+ end
+
+ end
+
+ class FakeWantAutomator < WantBase
+ def initalize
+ end
+
+ def submit_a_want(params={})
+ workshop = workshop_under_discussion(params[:name])
+ email = params[:email] || Factory.next(:email_address)
+ @lead = workshop.add_new_want(email)
+ end
+
+ def should_be_tracking_the_workshop
+ workshop_under_discussion.wants.count.should == 1
+ end
+
+ def has_error?(message)
+ @lead.valid?.should == false
+ @lead.errors.full_messages[0] =~ /#{message}/
+ end
+
+ end
+
+ def want_automator
+ if ENV['FULL_STACK']
+ @want_automator ||= WantAutomator.new
+ else
+ @want_automator ||= FakeWantAutomator.new
+ end
+ end
+end
+
+World(DSL::Want)
+
View
15 wantworkshop_demo/features/support/workshop_support.rb
@@ -0,0 +1,15 @@
+module DSL::Workshop
+ class WorkshopAutomator
+ include Capybara::DSL
+
+ def initialize
+ end
+ end
+
+ def workshop_automator
+ @workshop_automator ||= WorkshopAutomator.new
+ end
+
+end
+
+World(DSL::Workshop)

0 comments on commit 79a3385

Please sign in to comment.