Skip to content
This repository has been archived by the owner on Jun 20, 2022. It is now read-only.

Commit

Permalink
Add cucumber to manuals-frontend.
Browse files Browse the repository at this point in the history
Gem versions are pessimistically fixed to match those in other projects
(rspec 2 rather than 3, for example).

Also include two passing tests covering local manual and section
browsing and the fix introduced in 465ef06.
  • Loading branch information
kalleth committed Jun 12, 2014
1 parent 465ef06 commit 21a7d0d
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Gemfile
Expand Up @@ -24,3 +24,10 @@ group :development, :test do
gem 'byebug'
gem 'jasmine-rails'
end

group :test do
gem "cucumber-rails", "~> 1.4.0", require: false
# TODO: Check that rspec is fixed at 2 for a reason
gem "rspec-rails", "~> 2.14.0"
gem "launchy"
end
42 changes: 42 additions & 0 deletions Gemfile.lock
Expand Up @@ -26,6 +26,7 @@ GEM
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
addressable (2.3.6)
arel (4.0.2)
better_errors (1.1.0)
coderay (>= 1.0.0)
Expand All @@ -36,10 +37,29 @@ GEM
byebug (2.7.0)
columnize (~> 0.3)
debugger-linecache (~> 1.2)
capybara (2.3.0)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
coderay (1.1.0)
columnize (0.3.6)
cucumber (1.3.15)
builder (>= 2.1.2)
diff-lcs (>= 1.1.3)
gherkin (~> 2.12)
multi_json (>= 1.7.5, < 2.0)
multi_test (>= 0.1.1)
cucumber-rails (1.4.1)
capybara (>= 1.1.2, < 3)
cucumber (>= 1.3.8, < 2)
mime-types (~> 1.16)
nokogiri (~> 1.5)
rails (>= 3, < 5)
debug_inspector (0.0.2)
debugger-linecache (1.2.0)
diff-lcs (1.2.5)
erubis (2.7.0)
execjs (2.0.2)
gds-api-adapters (10.11.0)
Expand All @@ -48,6 +68,8 @@ GEM
null_logger
plek
rest-client (~> 1.6.3)
gherkin (2.12.2)
multi_json (~> 1.3)
govspeak (1.5.2)
htmlentities (~> 4)
kramdown (~> 0.13.3)
Expand All @@ -68,6 +90,8 @@ GEM
json (1.8.1)
kgio (2.9.2)
kramdown (0.13.8)
launchy (2.4.2)
addressable (~> 2.3)
link_header (0.0.8)
lrucache (0.1.4)
PriorityQueue (~> 0.1.2)
Expand All @@ -78,6 +102,7 @@ GEM
mime-types (1.25.1)
minitest (4.7.5)
multi_json (1.9.2)
multi_test (0.1.1)
nokogiri (1.5.11)
null_logger (0.0.1)
phantomjs (1.9.7.0)
Expand Down Expand Up @@ -107,6 +132,18 @@ GEM
rake (10.2.2)
rest-client (1.6.7)
mime-types (>= 1.16)
rspec-core (2.14.8)
rspec-expectations (2.14.5)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.6)
rspec-rails (2.14.2)
actionpack (>= 3.0)
activemodel (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
sanitize (2.0.6)
nokogiri (>= 1.4.4)
sass (3.2.19)
Expand Down Expand Up @@ -147,6 +184,8 @@ GEM
kgio (~> 2.6)
rack
raindrops (~> 0.7)
xpath (2.0.0)
nokogiri (~> 1.3)

PLATFORMS
ruby
Expand All @@ -155,13 +194,16 @@ DEPENDENCIES
better_errors
binding_of_caller
byebug
cucumber-rails (~> 1.4.0)
gds-api-adapters (= 10.11.0)
govspeak (= 1.5.2)
govuk_frontend_toolkit (= 1.2.0)
jasmine-rails
launchy
plek (= 1.7.0)
pry
rails (= 4.0.4)
rspec-rails (~> 2.14.0)
sass-rails (~> 4.0.2)
slimmer
uglifier (>= 1.3.0)
Expand Down
8 changes: 8 additions & 0 deletions config/cucumber.yml
@@ -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
12 changes: 12 additions & 0 deletions features/browsing-a-local-manual.feature
@@ -0,0 +1,12 @@
Feature: Browsing a local manual
As a member of the public
I want to be able to view a local manual and its sections

Scenario: Viewing an existing manual
When I view the employment income manual
And I click on the "EIM00500" subsection
Then I should see "EIM00500 - Employment income"

Scenario: Visiting a nonexistent document
When I visit a non-existent employment income manual section
Then I should get a response with status 404
Empty file.
21 changes: 21 additions & 0 deletions features/step_definitions/manual_steps.rb
@@ -0,0 +1,21 @@
When(/^I view the employment income manual$/) do
visit "/guidance/employment-income-manual"
end

When(/^I click on the "(.*?)" subsection$/) do |section|
within 'ol.section-links' do
click_on section
end
end

When(/^I visit a non\-existent employment income manual section$/) do
visit "/guidance/employment-income-manual/nonexistent-manual-section"
end

Then(/^I should see "(.*?)"$/) do |text|
expect(page).to have_content(text)
end

Then /^I should get a response with status (\d+)$/ do |status|
expect(page.status_code).to eq(status.to_i)
end
30 changes: 30 additions & 0 deletions features/support/env.rb
@@ -0,0 +1,30 @@
# 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'
require 'slimmer/test'

# Capybara defaults to CSS3 selectors rather than XPath.
# If you'd prefer to use XPath, just uncomment this line and adjust any
# selectors in your step definitions to use the XPath syntax.
# Capybara.default_selector = :xpath

# 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
65 changes: 65 additions & 0 deletions lib/tasks/cucumber.rake
@@ -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 => '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 => '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 => '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 the generic Rails test:prepare hook, append a no-op task that we can depend upon.
task '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
10 changes: 10 additions & 0 deletions script/cucumber
@@ -0,0 +1,10 @@
#!/usr/bin/env ruby

vendored_cucumber_bin = Dir["#{File.dirname(__FILE__)}/../vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
if vendored_cucumber_bin
load File.expand_path(vendored_cucumber_bin)
else
require 'rubygems' unless ENV['NO_RUBYGEMS']
require 'cucumber'
load Cucumber::BINARY
end

0 comments on commit 21a7d0d

Please sign in to comment.