Skip to content

Commit

Permalink
added test environment
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhgupta committed Jan 11, 2014
1 parent aa2a841 commit d043403
Show file tree
Hide file tree
Showing 13 changed files with 351 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -14,3 +14,4 @@
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
coverage
1 change: 1 addition & 0 deletions .rspec
@@ -0,0 +1 @@
--color
22 changes: 22 additions & 0 deletions .travis.yml
@@ -0,0 +1,22 @@
language: ruby
rvm:
- 2.1.0
- 1.9.3
- ruby-head
matrix:
fast_finish: true
allow_failures:
- rvm: ruby-head
env:
- DB=sqlite
- DB=mysql
- DB=postgresql
before_script:
- cp config/database.travis.yml config/database.yml
- mysql -e 'create database event_line_test;'
- psql -c 'create database event_line_test;' -U postgres
script:
- export RAILS_ENV=test
- bundle exec rake db:migrate --trace
- bundle exec rake db:test:prepare
- bundle exec rake
15 changes: 10 additions & 5 deletions Gemfile
Expand Up @@ -51,14 +51,19 @@ end

group :test, :development do
gem 'rspec-rails'
gem 'fuubar'
gem 'pg'
gem 'sqlite3'
end

group :test do
gem 'cucumber-rails'
gem 'capybara'
gem 'poltergeist'
gem 'factory_girl_rails'
gem 'launchy'
gem 'rb-fsevent'
gem 'poltergeist'
gem 'guard-rspec'
gem 'guard-cucumber'
gem 'database_cleaner'
gem 'factory_girl_rails'
gem 'terminal-notifier-guard'
gem 'coveralls', require: false
gem 'cucumber-rails', require: false
end
58 changes: 52 additions & 6 deletions Gemfile.lock
Expand Up @@ -35,6 +35,8 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
celluloid (0.15.2)
timers (~> 1.1.0)
cliver (0.3.2)
coderay (1.1.0)
coffee-rails (4.0.1)
Expand All @@ -44,6 +46,12 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.6.3)
coveralls (0.7.0)
multi_json (~> 1.3)
rest-client
simplecov (>= 0.7)
term-ansicolor
thor
cucumber (1.3.10)
builder (>= 2.1.2)
diff-lcs (>= 1.1.3)
Expand All @@ -57,18 +65,30 @@ GEM
rails (>= 3.0.0)
database_cleaner (1.2.0)
diff-lcs (1.2.5)
docile (1.1.2)
erubis (2.7.0)
execjs (2.0.2)
factory_girl (4.3.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.3.0)
factory_girl (~> 4.3.0)
railties (>= 3.0.0)
fuubar (1.3.2)
rspec (>= 2.14.0, < 3.1.0)
ruby-progressbar (~> 1.3)
ffi (1.9.3)
formatador (0.2.4)
gherkin (2.12.2)
multi_json (~> 1.3)
guard (2.2.5)
formatador (>= 0.2.4)
listen (~> 2.1)
lumberjack (~> 1.0)
pry (>= 0.9.12)
thor (>= 0.18.1)
guard-cucumber (1.4.0)
cucumber (>= 1.2.0)
guard (>= 1.1.0)
guard-rspec (4.0.3)
guard (>= 2.1.1)
rspec (~> 2.14)
hike (1.2.3)
i18n (0.6.5)
jbuilder (1.5.2)
Expand All @@ -80,6 +100,11 @@ GEM
json (1.8.1)
launchy (2.4.2)
addressable (~> 2.3)
listen (2.4.0)
celluloid (>= 0.15.2)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
lumberjack (1.0.4)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
Expand All @@ -92,6 +117,7 @@ GEM
mysql2 (0.3.14)
nokogiri (1.6.0)
mini_portile (~> 0.5.0)
pg (0.17.0)
poltergeist (1.5.0)
capybara (~> 2.1)
cliver (~> 0.3.1)
Expand Down Expand Up @@ -121,8 +147,13 @@ GEM
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.1.0)
rb-fsevent (0.9.4)
rb-inotify (0.9.3)
ffi (>= 0.5.0)
rdoc (3.12.2)
json (~> 1.4)
rest-client (1.6.7)
mime-types (>= 1.16)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
Expand All @@ -138,7 +169,6 @@ GEM
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
ruby-progressbar (1.3.2)
sass (3.2.12)
sass-rails (4.0.1)
railties (>= 4.0.0, < 5.0)
Expand All @@ -149,6 +179,11 @@ GEM
rdoc (~> 3.10)
shotgun (0.9)
rack (>= 1.0)
simplecov (0.8.2)
docile (~> 1.1.0)
multi_json
simplecov-html (~> 0.8.0)
simplecov-html (0.8.0)
slop (3.4.7)
sprockets (2.10.1)
hike (~> 1.2)
Expand All @@ -159,10 +194,16 @@ GEM
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (~> 2.8)
sqlite3 (1.3.8)
term-ansicolor (1.2.2)
tins (~> 0.8)
terminal-notifier-guard (1.5.3)
thor (0.18.1)
thread_safe (0.1.3)
atomic
tilt (1.4.1)
timers (1.1.0)
tins (0.13.1)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
Expand All @@ -180,22 +221,27 @@ PLATFORMS
ruby

DEPENDENCIES
capybara
coffee-rails (~> 4.0.0)
coveralls
cucumber-rails
database_cleaner
factory_girl_rails
fuubar
guard-cucumber
guard-rspec
jbuilder (~> 1.2)
jquery-rails
launchy
mysql2
pg
poltergeist
pry-rails
rails (= 4.0.1)
rb-fsevent
rspec-rails
sass-rails (~> 4.0.0)
sdoc
shotgun
sqlite3
terminal-notifier-guard
turbolinks
uglifier (>= 1.3.0)
32 changes: 32 additions & 0 deletions Guardfile
@@ -0,0 +1,32 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

notification :terminal_notifier

guard :rspec, cmd: "bundle exec rspec --color" do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }

# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }

# Capybara features specs
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }

# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end


guard 'cucumber', cmd: "bundle exec cucumber --color" do
watch(%r{^features/.+\.feature$})
watch(%r{^features/support/.+$}) { 'features' }
watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
end
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
32 changes: 32 additions & 0 deletions config/database.travis.yml
@@ -0,0 +1,32 @@
sqlite: &sqlite
adapter: sqlite3
database: db/<%= Rails.env %>.sqlite3

mysql: &mysql
adapter: mysql2
username: root
password:
database: event_line_<%= Rails.env %>
encoding: utf8

postgresql: &postgresql
adapter: postgresql
username: postgres
password:
database: event_line_<%= Rails.env %>
min_messages: ERROR

defaults: &defaults
pool: 5
timeout: 5000
host: localhost
<<: *<%= ENV['DB'] || "mysql" %>

development:
<<: *defaults

test:
<<: *defaults

production:
<<: *defaults
5 changes: 4 additions & 1 deletion config/database.yml
Expand Up @@ -20,7 +20,7 @@ development:
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
test: &test
adapter: mysql2
encoding: utf8
database: event_line_test
Expand All @@ -37,3 +37,6 @@ production:
username: root
password: password
socket: /tmp/mysql.sock

cucumber:
<<: *test
65 changes: 65 additions & 0 deletions features/support/env.rb
@@ -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.

# require coveralls coverage
require 'coveralls'
Coveralls.wear!

# require cucumber
require 'cucumber/rails'

# load up factory girl methods inside cucumber
World(FactoryGirl::Syntax::Methods)

# 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

# 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 Cucumber::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 comments on commit d043403

Please sign in to comment.