Permalink
Browse files

Setup test environment with rspec and cucumber

  • Loading branch information...
1 parent 1305cab commit dea31d44e053488e2ee67ddfa72f173a188bfba3 David Davis committed Jan 22, 2012
View
1 .rspec
@@ -0,0 +1 @@
+--colour
View
3 Gemfile
@@ -31,6 +31,9 @@ end
# gem 'ruby-debug19', :require => 'ruby-debug'
group :test do
+ gem 'cucumber-rails'
+ gem 'database_cleaner'
+ gem 'rspec-rails', "~> 2.8"
# Pretty printed test output
gem 'turn', '0.8.2', :require => false
end
View
52 Gemfile.lock
@@ -37,6 +37,15 @@ GEM
bson_ext (1.5.2)
bson (= 1.5.2)
builder (3.0.0)
+ 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.0)
+ ffi (~> 1.0.6)
coderay (1.0.5)
coffee-rails (3.1.1)
coffee-script (>= 2.2.0)
@@ -46,20 +55,35 @@ GEM
execjs
coffee-script-source (1.2.0)
columnize (0.3.6)
+ cucumber (1.1.4)
+ builder (>= 2.1.2)
+ diff-lcs (>= 1.1.2)
+ gherkin (~> 2.7.1)
+ json (>= 1.4.6)
+ term-ansicolor (>= 1.0.6)
+ cucumber-rails (1.2.1)
+ capybara (>= 1.1.2)
+ cucumber (>= 1.1.3)
+ nokogiri (>= 1.5.0)
+ database_cleaner (0.7.1)
devise (1.5.3)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.0.3)
warden (~> 1.1)
+ diff-lcs (1.1.3)
erubis (2.7.0)
execjs (1.2.13)
multi_json (~> 1.0)
fakefs (0.4.0)
+ ffi (1.0.11)
+ gherkin (2.7.4)
+ json (>= 1.4.6)
hike (1.2.1)
i18n (0.6.0)
jquery-rails (1.0.19)
railties (~> 3.0)
thor (~> 0.14)
- json (1.6.4)
+ json (1.6.5)
linecache19 (0.5.13)
ruby_core_source (>= 0.1.4)
mail (2.3.0)
@@ -74,6 +98,7 @@ GEM
mongo (~> 1.3)
tzinfo (~> 0.3.22)
multi_json (1.0.4)
+ nokogiri (1.5.0)
orm_adapter (0.0.6)
polyglot (0.3.3)
rack (1.3.6)
@@ -104,6 +129,19 @@ GEM
rdoc (3.12)
json (~> 1.4)
rinku (1.5.0)
+ rspec (2.8.0)
+ rspec-core (~> 2.8.0)
+ rspec-expectations (~> 2.8.0)
+ rspec-mocks (~> 2.8.0)
+ rspec-core (2.8.0)
+ rspec-expectations (2.8.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.8.0)
+ rspec-rails (2.8.1)
+ actionpack (>= 3.0)
+ activesupport (>= 3.0)
+ railties (>= 3.0)
+ rspec (~> 2.8.0)
ruby-debug-base19 (0.11.26)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
@@ -115,16 +153,23 @@ GEM
ruby_core_source (0.1.5)
archive-tar-minitar (>= 0.5.2)
rubycop (0.5.1)
+ rubyzip (0.9.5)
sass (3.1.12)
sass-rails (3.1.5)
actionpack (~> 3.1.0)
railties (~> 3.1.0)
sass (~> 3.1.10)
tilt (~> 1.3.2)
+ selenium-webdriver (2.17.0)
+ childprocess (>= 0.2.5)
+ ffi (~> 1.0.9)
+ multi_json (~> 1.0.4)
+ rubyzip
sprockets (2.0.3)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
+ term-ansicolor (1.0.7)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
@@ -138,6 +183,8 @@ GEM
multi_json (>= 1.0.2)
warden (1.1.0)
rack (>= 1.0)
+ xpath (0.1.4)
+ nokogiri (~> 1.3)
PLATFORMS
ruby
@@ -146,13 +193,16 @@ DEPENDENCIES
bson_ext (~> 1.5)
coderay (~> 1.0.5)
coffee-rails (~> 3.1.1)
+ cucumber-rails
+ database_cleaner
devise (~> 1.5.3)
fakefs
jquery-rails
linecache19 (= 0.5.13)
mongoid (~> 2.4)
rails (= 3.1.3)
rinku
+ rspec-rails (~> 2.8)
ruby-debug-base19 (= 0.11.26)
ruby-debug19 (= 0.11.6)
rubycop
View
8 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
View
56 features/support/env.rb
@@ -0,0 +1,56 @@
+# 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 = :truncation
+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
+# DatabaseCleaner.strategy = :truncation, {:except => %w[widgets]}
+# 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
+
View
65 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 => '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
View
10 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
View
32 spec/spec_helper.rb
@@ -0,0 +1,32 @@
+# This file is copied to spec/ when you run 'rails generate rspec:install'
+ENV["RAILS_ENV"] ||= 'test'
+require File.expand_path("../../config/environment", __FILE__)
+require 'rspec/rails'
+require 'rspec/autorun'
+
+# Requires supporting ruby files with custom matchers and macros, etc,
+# in spec/support/ and its subdirectories.
+Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
+
+RSpec.configure do |config|
+ # ## Mock Framework
+ #
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
+ #
+ # config.mock_with :mocha
+ # config.mock_with :flexmock
+ # config.mock_with :rr
+
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
+
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
+ # examples within a transaction, remove the following line or assign false
+ # instead of true.
+ config.use_transactional_fixtures = true
+
+ # If true, the base class of anonymous controllers will be inferred
+ # automatically. This will be the default behavior in future versions of
+ # rspec-rails.
+ config.infer_base_class_for_anonymous_controllers = false
+end
View
0 test/fixtures/.gitkeep
No changes.
View
11 test/fixtures/following.yml
@@ -1,11 +0,0 @@
-# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
-
-# This model initially had no columns defined. If you add columns to the
-# model remove the '{}' from the fixture names and add the columns immediately
-# below each fixture, per the syntax in the comments below
-#
-one: {}
-# column: value
-#
-two: {}
-# column: value
View
13 test/fixtures/problems.yml
@@ -1,13 +0,0 @@
-# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
-
-one:
- title: MyString
- instructions: MyText
- code: MyText
- difficulty: MyString
-
-two:
- title: MyString
- instructions: MyText
- code: MyText
- difficulty: MyString
View
11 test/fixtures/solutions.yml
@@ -1,11 +0,0 @@
-# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
-
-one:
- problem:
- code: MyText
- user:
-
-two:
- problem:
- code: MyText
- user:
View
9 test/fixtures/tags.yml
@@ -1,9 +0,0 @@
-# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
-
-one:
- name: MyString
- problem:
-
-two:
- name: MyString
- problem:
View
11 test/fixtures/users.yml
@@ -1,11 +0,0 @@
-# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
-
-# This model initially had no columns defined. If you add columns to the
-# model remove the '{}' from the fixture names and add the columns immediately
-# below each fixture, per the syntax in the comments below
-#
-one: {}
-# column: value
-#
-two: {}
-# column: value
View
11 test/fixtures/votes.yml
@@ -1,11 +0,0 @@
-# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
-
-one:
- up: false
- user:
- solution:
-
-two:
- up: false
- user:
- solution:
View
0 test/functional/.gitkeep
No changes.
View
49 test/functional/following_controller_test.rb
@@ -1,49 +0,0 @@
-require 'test_helper'
-
-class FollowingControllerTest < ActionController::TestCase
- setup do
- @following = following(:one)
- end
-
- test "should get index" do
- get :index
- assert_response :success
- assert_not_nil assigns(:following)
- end
-
- test "should get new" do
- get :new
- assert_response :success
- end
-
- test "should create following" do
- assert_difference('Following.count') do
- post :create, following: @following.attributes
- end
-
- assert_redirected_to following_path(assigns(:following))
- end
-
- test "should show following" do
- get :show, id: @following.to_param
- assert_response :success
- end
-
- test "should get edit" do
- get :edit, id: @following.to_param
- assert_response :success
- end
-
- test "should update following" do
- put :update, id: @following.to_param, following: @following.attributes
- assert_redirected_to following_path(assigns(:following))
- end
-
- test "should destroy following" do
- assert_difference('Following.count', -1) do
- delete :destroy, id: @following.to_param
- end
-
- assert_redirected_to following_index_path
- end
-end
View
49 test/functional/problems_controller_test.rb
@@ -1,49 +0,0 @@
-require 'test_helper'
-
-class ProblemsControllerTest < ActionController::TestCase
- setup do
- @problem = problems(:one)
- end
-
- test "should get index" do
- get :index
- assert_response :success
- assert_not_nil assigns(:problems)
- end
-
- test "should get new" do
- get :new
- assert_response :success
- end
-
- test "should create problem" do
- assert_difference('Problem.count') do
- post :create, problem: @problem.attributes
- end
-
- assert_redirected_to problem_path(assigns(:problem))
- end
-
- test "should show problem" do
- get :show, id: @problem.to_param
- assert_response :success
- end
-
- test "should get edit" do
- get :edit, id: @problem.to_param
- assert_response :success
- end
-
- test "should update problem" do
- put :update, id: @problem.to_param, problem: @problem.attributes
- assert_redirected_to problem_path(assigns(:problem))
- end
-
- test "should destroy problem" do
- assert_difference('Problem.count', -1) do
- delete :destroy, id: @problem.to_param
- end
-
- assert_redirected_to problems_path
- end
-end
View
49 test/functional/solutions_controller_test.rb
@@ -1,49 +0,0 @@
-require 'test_helper'
-
-class SolutionsControllerTest < ActionController::TestCase
- setup do
- @solution = solutions(:one)
- end
-
- test "should get index" do
- get :index
- assert_response :success
- assert_not_nil assigns(:solutions)
- end
-
- test "should get new" do
- get :new
- assert_response :success
- end
-
- test "should create solution" do
- assert_difference('Solution.count') do
- post :create, solution: @solution.attributes
- end
-
- assert_redirected_to solution_path(assigns(:solution))
- end
-
- test "should show solution" do
- get :show, id: @solution.to_param
- assert_response :success
- end
-
- test "should get edit" do
- get :edit, id: @solution.to_param
- assert_response :success
- end
-
- test "should update solution" do
- put :update, id: @solution.to_param, solution: @solution.attributes
- assert_redirected_to solution_path(assigns(:solution))
- end
-
- test "should destroy solution" do
- assert_difference('Solution.count', -1) do
- delete :destroy, id: @solution.to_param
- end
-
- assert_redirected_to solutions_path
- end
-end
View
9 test/functional/static_controller_test.rb
@@ -1,9 +0,0 @@
-require 'test_helper'
-
-class StaticControllerTest < ActionController::TestCase
- test "should get index" do
- get :index
- assert_response :success
- end
-
-end
View
9 test/functional/users_controller_test.rb
@@ -1,9 +0,0 @@
-require 'test_helper'
-
-class UsersControllerTest < ActionController::TestCase
- test "should get index" do
- get :index
- assert_response :success
- end
-
-end
View
49 test/functional/votes_controller_test.rb
@@ -1,49 +0,0 @@
-require 'test_helper'
-
-class VotesControllerTest < ActionController::TestCase
- setup do
- @vote = votes(:one)
- end
-
- test "should get index" do
- get :index
- assert_response :success
- assert_not_nil assigns(:votes)
- end
-
- test "should get new" do
- get :new
- assert_response :success
- end
-
- test "should create vote" do
- assert_difference('Vote.count') do
- post :create, vote: @vote.attributes
- end
-
- assert_redirected_to vote_path(assigns(:vote))
- end
-
- test "should show vote" do
- get :show, id: @vote.to_param
- assert_response :success
- end
-
- test "should get edit" do
- get :edit, id: @vote.to_param
- assert_response :success
- end
-
- test "should update vote" do
- put :update, id: @vote.to_param, vote: @vote.attributes
- assert_redirected_to vote_path(assigns(:vote))
- end
-
- test "should destroy vote" do
- assert_difference('Vote.count', -1) do
- delete :destroy, id: @vote.to_param
- end
-
- assert_redirected_to votes_path
- end
-end
View
0 test/integration/.gitkeep
No changes.
View
12 test/performance/browsing_test.rb
@@ -1,12 +0,0 @@
-require 'test_helper'
-require 'rails/performance_test_help'
-
-class BrowsingTest < ActionDispatch::PerformanceTest
- # Refer to the documentation for all available options
- # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
- # :output => 'tmp/performance', :formats => [:flat] }
-
- def test_homepage
- get '/'
- end
-end
View
7 test/test_helper.rb
@@ -1,7 +0,0 @@
-ENV["RAILS_ENV"] = "test"
-require File.expand_path('../../config/environment', __FILE__)
-require 'rails/test_help'
-
-class ActiveSupport::TestCase
- # Add more helper methods to be used by all tests here...
-end
View
0 test/unit/.gitkeep
No changes.
View
7 test/unit/following_test.rb
@@ -1,7 +0,0 @@
-require 'test_helper'
-
-class FollowingTest < ActiveSupport::TestCase
- # test "the truth" do
- # assert true
- # end
-end
View
4 test/unit/helpers/following_helper_test.rb
@@ -1,4 +0,0 @@
-require 'test_helper'
-
-class FollowingHelperTest < ActionView::TestCase
-end
View
4 test/unit/helpers/problems_helper_test.rb
@@ -1,4 +0,0 @@
-require 'test_helper'
-
-class ProblemsHelperTest < ActionView::TestCase
-end
View
4 test/unit/helpers/solutions_helper_test.rb
@@ -1,4 +0,0 @@
-require 'test_helper'
-
-class SolutionsHelperTest < ActionView::TestCase
-end
View
4 test/unit/helpers/static_helper_test.rb
@@ -1,4 +0,0 @@
-require 'test_helper'
-
-class StaticHelperTest < ActionView::TestCase
-end
View
4 test/unit/helpers/users_helper_test.rb
@@ -1,4 +0,0 @@
-require 'test_helper'
-
-class UsersHelperTest < ActionView::TestCase
-end
View
4 test/unit/helpers/votes_helper_test.rb
@@ -1,4 +0,0 @@
-require 'test_helper'
-
-class VotesHelperTest < ActionView::TestCase
-end
View
7 test/unit/problem_test.rb
@@ -1,7 +0,0 @@
-require 'test_helper'
-
-class ProblemTest < ActiveSupport::TestCase
- # test "the truth" do
- # assert true
- # end
-end
View
7 test/unit/solution_test.rb
@@ -1,7 +0,0 @@
-require 'test_helper'
-
-class SolutionTest < ActiveSupport::TestCase
- # test "the truth" do
- # assert true
- # end
-end
View
7 test/unit/tag_test.rb
@@ -1,7 +0,0 @@
-require 'test_helper'
-
-class TagTest < ActiveSupport::TestCase
- # test "the truth" do
- # assert true
- # end
-end
View
7 test/unit/user_test.rb
@@ -1,7 +0,0 @@
-require 'test_helper'
-
-class UserTest < ActiveSupport::TestCase
- # test "the truth" do
- # assert true
- # end
-end
View
7 test/unit/vote_test.rb
@@ -1,7 +0,0 @@
-require 'test_helper'
-
-class VoteTest < ActiveSupport::TestCase
- # test "the truth" do
- # assert true
- # end
-end

0 comments on commit dea31d4

Please sign in to comment.