Permalink
Browse files

adding cucumber test for the general request form

  • Loading branch information...
1 parent 0eedf1f commit ad40e776aebd39056543ae0e07ef65ede54c7c0c @benilovj benilovj committed Nov 16, 2012
View
@@ -22,6 +22,9 @@ group :test do
gem "mocha", "0.12.6", require: false
gem "shoulda", "~> 3.3.2"
gem "webmock", "1.8.11"
+ gem 'capybara', '1.1.2'
+ gem 'poltergeist', '0.7.0'
+ gem 'cucumber-rails', '1.3.0', :require => false
end
gem 'unicorn', '4.3.1'
View
@@ -37,6 +37,15 @@ GEM
mime-types
xml-simple
builder (3.0.4)
+ capybara (1.1.2)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ selenium-webdriver (~> 2.0)
+ xpath (~> 0.1.4)
+ childprocess (0.3.5)
+ ffi (~> 1.0, >= 1.0.6)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
@@ -45,14 +54,28 @@ GEM
execjs
coffee-script-source (1.3.3)
crack (0.3.1)
+ cucumber (1.2.1)
+ builder (>= 2.1.2)
+ diff-lcs (>= 1.1.3)
+ gherkin (~> 2.11.0)
+ json (>= 1.4.6)
+ cucumber-rails (1.3.0)
+ capybara (>= 1.1.2)
+ cucumber (>= 1.1.8)
+ nokogiri (>= 1.5.0)
+ diff-lcs (1.1.3)
erubis (2.7.0)
+ eventmachine (1.0.0)
exception_notification (2.4.1)
execjs (1.4.0)
multi_json (~> 1.0)
faraday (0.8.4)
multipart-post (~> 1.1)
faraday_middleware (0.8.8)
faraday (>= 0.7.4, < 0.9)
+ faye-websocket (0.4.6)
+ eventmachine (>= 0.12.0)
+ ffi (1.1.5)
formtastic (2.2.1)
actionpack (>= 3.0)
formtastic-bootstrap (2.0.0)
@@ -63,8 +86,11 @@ GEM
rack-accept (~> 0.4.4)
rails (>= 3.0.0)
warden (~> 1.2)
+ gherkin (2.11.2)
+ json (>= 1.4.6)
hashie (1.2.0)
hike (1.2.1)
+ http_parser.rb (0.5.3)
httpauth (0.2.0)
i18n (0.6.1)
inflection (1.0.0)
@@ -77,6 +103,8 @@ GEM
multi_json (>= 1.0)
kgio (2.7.4)
libv8 (3.3.10.4)
+ libwebsocket (0.1.5)
+ addressable
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
@@ -87,6 +115,7 @@ GEM
metaclass (~> 0.0.1)
multi_json (1.3.6)
multipart-post (1.1.5)
+ nokogiri (1.5.5)
oauth2 (0.8.0)
faraday (~> 0.8)
httpauth (~> 0.1)
@@ -103,6 +132,12 @@ GEM
omniauth (~> 1.0)
plek (0.5.0)
builder
+ poltergeist (0.7.0)
+ capybara (~> 1.1)
+ childprocess (~> 0.3)
+ faye-websocket (~> 0.4, >= 0.4.4)
+ http_parser.rb (~> 0.5.3)
+ multi_json (~> 1.0)
polyglot (0.3.3)
rack (1.4.1)
rack-accept (0.4.5)
@@ -132,11 +167,17 @@ GEM
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
+ rubyzip (0.9.9)
sass (3.2.1)
sass-rails (3.2.5)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
+ selenium-webdriver (2.25.0)
+ childprocess (>= 0.2.5)
+ libwebsocket (~> 0.1.3)
+ multi_json (~> 1.0)
+ rubyzip
shoulda (3.3.2)
shoulda-context (~> 1.0.1)
shoulda-matchers (~> 1.4.1)
@@ -168,6 +209,8 @@ GEM
addressable (>= 2.2.7)
crack (>= 0.1.7)
xml-simple (1.1.1)
+ xpath (0.1.4)
+ nokogiri (~> 1.3)
zendesk_api (0.1.2)
faraday (>= 0.8.0)
faraday_middleware (>= 0.8.7)
@@ -182,13 +225,16 @@ PLATFORMS
DEPENDENCIES
aws-ses
+ capybara (= 1.1.2)
coffee-rails (~> 3.2.1)
+ cucumber-rails (= 1.3.0)
exception_notification (~> 2.4.1)
formtastic-bootstrap (= 2.0.0)
gds-sso (= 2.1.0)
jquery-rails
mocha (= 0.12.6)
plek (= 0.5.0)
+ poltergeist (= 0.7.0)
rails (= 3.2.8)
sass-rails (~> 3.2.3)
shoulda (~> 3.3.2)
View
@@ -0,0 +1,8 @@
+<%
+rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
+rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
+std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
+%>
+default: <%= std_opts %> features
+wip: --tags @wip:3 --wip features
+rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
@@ -0,0 +1,26 @@
+Feature: General requests
+ In order to provide GDS with feedback
+ As a government employee
+ I want a means to contact GDS in the cases when my request does not covered by the other forms
+
+ Background:
+ * the following user has SSO access:
+ | Name | Email | Job title | Organisation |
+ | John Smith | john.smith@email.com | Developer | Cabinet Office |
+
+ Scenario: successful request
+ When the user submits the following general request:
+ | Details | URL |
+ | The site is down | http://www.gov.uk |
+ Then the following ticket is raised in ZenDesk:
+ | Subject | Requester email | Requester name | Job title | Organisation |
+ | Govt Agency General Issue | john.smith@email.com | John Smith | Developer | cabinet_office |
+ And the ticket is tagged with "govt_agency_general"
+ And the comment on the ticket is:
+ """
+ [Url]
+ http://www.gov.uk
+
+ [Additional]
+ The site is down
+ """
@@ -0,0 +1,19 @@
+When /^the user submits the following general request:$/ do |request_details_table|
+ request_details = request_details_table.hashes.first
+
+ visit '/'
+
+ click_on "General"
+
+ assert page.has_content?("Report a problem")
+
+ fill_in "Name", :with => @user_details["Name"]
+ fill_in "Email", :with => @user_details["Email"]
+ fill_in "Job title", :with => @user_details["Job title"]
+ select @user_details["Organisation"], :from => 'Organisation'
+
+ fill_in "Details", :with => request_details['Details']
+ fill_in "URL (if applicable)", :with => request_details['URL']
+
+ click_on "Submit"
+end
@@ -0,0 +1,6 @@
+Given /^the following user has SSO access:$/ do |user_details|
+ user = stub_everything('user', :name => "user", :has_permission? => true)
+ @user_details = user_details.hashes.first
+
+ login_as user
+end
@@ -0,0 +1,18 @@
+Then /^the following ticket is raised in ZenDesk:$/ do |ticket_properties_table|
+ expected_ticket_props = ticket_properties_table.hashes.first
+ @raised_ticket = @zendesk_api.ticket
+
+ assert_equal expected_ticket_props["Subject"], @raised_ticket.subject
+ assert_equal expected_ticket_props["Requester email"], @raised_ticket.email
+ assert_equal expected_ticket_props["Requester name"], @raised_ticket.name
+ assert_equal expected_ticket_props["Job title"], @raised_ticket.job
+ assert_equal expected_ticket_props["Organisation"], @raised_ticket.organisation
+end
+
+Then /^the ticket is tagged with "(.*?)"$/ do |expected_tags|
+ assert_equal expected_tags, @raised_ticket.tags.join(" ")
+end
+
+Then /^the comment on the ticket is:$/ do |expected_comment_string|
+ assert_equal expected_comment_string, @raised_ticket.comment
+end
@@ -0,0 +1,9 @@
+require 'capybara/poltergeist'
+
+Capybara.register_driver :rack_test do |app|
+ Capybara::RackTest::Driver.new(app, :browser => :chrome)
+end
+Capybara.register_driver :poltergeist do |app|
+ Capybara::Poltergeist::Driver.new(app, timeout: 5, debug: true)
+end
+Capybara.javascript_driver = :poltergeist
View
@@ -0,0 +1,59 @@
+# 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 'cucumber/rails'
+
+# 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
+
+# Remove/comment out the lines below if your app doesn't have a database.
+# For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
+# 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
+
+# You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios.
+# See the DatabaseCleaner documentation for details. Example:
+#
+# Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do
+# # { :except => [:widgets] } may not do what you expect here
+# # as tCucumber::Rails::Database.javascript_strategy overrides
+# # this setting.
+# DatabaseCleaner.strategy = :truncation
+# end
+#
+# Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do
+# DatabaseCleaner.strategy = :transaction
+# end
+#
+
+# Possible values are :truncation and :transaction
+# The :transaction strategy is faster, but might give you threading problems.
+# See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature
+Cucumber::Rails::Database.javascript_strategy = :truncation
+
@@ -0,0 +1,9 @@
+require "warden/test/helpers"
+
+module GdsSsoHelper
+ def login_as(user)
+ GDS::SSO.test_user = user
+ end
+end
+
+World(GdsSsoHelper)
@@ -0,0 +1,4 @@
+Before do
+ stub_zendesk_organisation_list
+ stub_zendesk_ticket_submission
+end
@@ -0,0 +1,3 @@
+require 'webmock/cucumber'
+
+WebMock.disable_net_connect!(:allow_localhost => true)
@@ -0,0 +1,5 @@
+require_relative '../../test/zendesk_organisation_list_helper'
+require_relative '../../test/zendesk_api_stubs'
+
+World(ZendeskOrganisationListHelper)
+World(ZendeskApiStubsHelper)
View
@@ -11,7 +11,7 @@ def to_s
end
def applies?
- @data_provider.send("#{@field_name}") && !@data_provider.send("#{@field_name}").nil?
+ @data_provider.respond_to?(@field_name) && !field_value.nil? && !field_value.empty?
end
def field_value
View
@@ -0,0 +1,65 @@
+# 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.
+
+
+unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
+
+vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
+$LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
+
+begin
+ require 'cucumber/rake/task'
+
+ namespace :cucumber do
+ Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
+ t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
+ t.fork = true # You may get faster startup if you set this to false
+ t.profile = 'default'
+ end
+
+ Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
+ t.binary = vendored_cucumber_bin
+ t.fork = true # You may get faster startup if you set this to false
+ t.profile = 'wip'
+ end
+
+ Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t|
+ t.binary = vendored_cucumber_bin
+ t.fork = true # You may get faster startup if you set this to false
+ t.profile = 'rerun'
+ end
+
+ desc 'Run all features'
+ task :all => [:ok, :wip]
+
+ task :statsetup do
+ require 'rails/code_statistics'
+ ::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features')
+ ::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features')
+ end
+ end
+ desc 'Alias for cucumber:ok'
+ task :cucumber => 'cucumber:ok'
+
+ task :default => :cucumber
+
+ task :features => :cucumber do
+ STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
+ end
+
+ # In case we don't have ActiveRecord, append a no-op task that we can depend upon.
+ task 'db:test:prepare' do
+ end
+
+ task :stats => 'cucumber:statsetup'
+rescue LoadError
+ desc 'cucumber rake task not available (cucumber not installed)'
+ task :cucumber do
+ abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
+ end
+end
+
+end
Oops, something went wrong.

0 comments on commit ad40e77

Please sign in to comment.