Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add basic cucumber tests

  • Loading branch information...
commit e91dbb529e86bcbe330712264e3d78363095439c 1 parent b7b97d7
Veezus Kreist veezus authored
9 features/create_a_network.feature
View
@@ -0,0 +1,9 @@
+Feature: Create a network
+
+ Scenario: An admin creates an sfbay network
+ Given I am logged in as a "admin"
+ And I visit the new admin network page
+ And I fill in "Name" with "sfbay"
+ And I fill in "Display Name" with "Bay Area"
+ And I press "Save changes"
+ Then I should see an "All networks" link
21 features/create_a_pitch.feature
View
@@ -0,0 +1,21 @@
+Feature: Create a pitch
+
+ Scenario: A reporter creates a pitch
+ Given I am logged in as a "reporter"
+ And A sfbay network exists
+ And A consumer protection topic exists
+ And I visit the new pitch page
+ And I select "Bay Area" from "network_select"
+ And I fill in "Your Pitch's Headline" with "Pitch Headline"
+ And I fill in "pitch[short_description]" with "Lots of reasons!"
+ And I check "pitch[topics_params][]"
+ And I fill in "pitch[extended_description]" with "I can has helps?"
+ And I fill in "pitch[skills]" with "I got skillz yo!"
+ And I fill in "pitch[requested_amount]" with "1000"
+ And I check "Text"
+ And I fill in "pitch[delivery_description]" with "Some stuff to be delivered"
+ And I fill in "pitch[featured_image_caption]" with "A caption"
+ And I check "pitch[contract_agreement]"
+ When I press "Create a pitch"
+ Then I should be on the show pitch page
+
10 features/create_a_story.feature
View
@@ -0,0 +1,10 @@
+Feature: Create a story from a pitch
+
+Scenario: A reporter creates a story from a pitch
+ Given I am logged in as a "reporter"
+ And I have created a "pitch"
+ And A "donation" exists for the "pitch"
+ And I visit the myspot pitches page
+ And I follow "Accept"
+ When I follow "Report"
+ Then I should be on the edit story page
16 features/login.feature
View
@@ -0,0 +1,16 @@
+Feature: Start a story
+
+ Scenario: Not logged in
+ Given I am at the Home Page
+ When I follow "Start a Story"
+ Then I should see an "email" text field
+
+ Scenario: A citizen should see the tips/new page
+ Given I am logged in as a "citizen"
+ When I follow "Start a Story"
+ Then I should see a tag of "h3" with "Create a Tip"
+
+ Scenario: A reporter should see the pitches/new page
+ Given I am logged in as a "reporter"
+ When I follow "Start a Story"
+ Then I should see a tag of "h3" with "Create a Pitch"
20 features/step_definitions/spotus_steps.rb
View
@@ -0,0 +1,20 @@
+Given "A sfbay network exists" do
+ Network.create!(:name => 'sfbay', :display_name => 'Bay Area')
+end
+
+Given "A consumer protection topic exists" do
+ Topic.create!(:name => 'Consumer protection')
+end
+
+Given /^I have created a "(.*)"$/ do |model_name|
+ set_instance_variable(model_name, model_name.classify.constantize.create!(Factory(model_name.to_sym, :user => @user).attributes))
+end
+
+Given /^A "(.*)" exists$/ do |model_name|
+ set_instance_variable(model_name, model_name.classify.constantize.create!(Factory(model_name.to_sym).attributes))
+end
+
+Given /^A "(.*)" exists for the "(.*)"$/ do |child, parent|
+ child.classify.constantize.create!(Factory(child.to_sym, parent.to_sym => get_instance_variable(parent)).attributes)
+end
+
20 features/step_definitions/user_steps.rb
View
@@ -0,0 +1,20 @@
+Given 'I have a citizen account' do
+ @user = Factory(:citizen)
+end
+
+Given 'I am at the Home Page' do
+ visit(root_url)
+end
+
+Given 'I am logged out' do
+ delete "/session"
+end
+
+Given /^I am logged in as a "(.*)"$/ do |model_name|
+ @user ||= Factory(model_name.to_sym)
+ @user.activate! unless @user.active?
+ visit(new_session_path)
+ fill_in("email", :with => @user.email)
+ fill_in("password", :with => @user.password)
+ click_button("Login")
+end
14 features/step_definitions/webrat_steps.rb
View
@@ -84,6 +84,10 @@
current_dom.inner_text.should include_text(text)
end
+Then /^I should see a tag of "(.*)" with "(.*)"$/ do |tag, text|
+ response.should have_tag(tag, /#{text}/i)
+end
+
Then /^I should see an? "(.*)" link$/ do |text|
response.should have_tag("a", /#{text}/i)
end
@@ -141,6 +145,16 @@
visit(human_route(name))
end
+When /^I view the current ([\w -]+?) ?page$/ do |name|
+ visit(human_route_for_current(name))
+end
+
+
+Then /^I should be on the (.*?) page$/ do |path|
+ action, controller = path.split(/\s/)
+ response.should render_template("#{controller.pluralize}/#{action}")
+end
+
Given /^I am on the (.*)$/ do |fragment|
When "I visit the #{fragment}"
end
37 features/support/env.rb
View
@@ -4,13 +4,42 @@
require 'cucumber/rails/world'
require 'cucumber/formatters/unicode' # Comment out this line if you don't want Cucumber Unicode support
Cucumber::Rails.use_transactional_fixtures
-
+require 'cucumber/rails/rspec'
+require 'webrat/rspec-rails'
require 'webrat'
+module HumanMethods
+ def dehumanize(string)
+ string.gsub(/\W+/,'_')
+ end
+
+ def human_route(name)
+ send("#{dehumanize(name).sub(/^home$/,'root')}_path")
+ end
+
+ def human_route_for_current(name)
+ instance = name.split(' ').last
+ instance = "@#{instance}"
+ "#{dehumanize(name)}_path(#{instance})"
+ end
+end
+
+World do |world|
+ world.extend(HumanMethods)
+ world.extend(HelperMethods)
+end
+
Webrat.configure do |config|
config.mode = :rails
end
-# Comment out the next two lines if you're not using RSpec's matchers (should / should_not) in your steps.
-require 'cucumber/rails/rspec'
-require 'webrat/rspec-rails'
+module HelperMethods
+ def set_instance_variable(name, value)
+ instance_variable_name = "@#{name}"
+ instance_variable_set(instance_variable_name, value)
+ end
+ def get_instance_variable(name)
+ instance_variable_name = "@#{name}"
+ instance_variable_get(instance_variable_name)
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.