Permalink
Browse files

Move test suite to Rails 3.1

  • Loading branch information...
1 parent ce7cf97 commit dfb3cb040a0d5e82c32c78212b00279cc94496a7 @mattyoho committed Oct 11, 2011
View
1 .gitignore
@@ -1,5 +1,4 @@
tmp
pkg
.bundle
-/Gemfile
*.lock
View
17 Gemfile
@@ -0,0 +1,17 @@
+source "http://rubygems.org"
+
+lib = File.expand_path("../lib", __FILE__)
+$:.unshift lib unless $:.include?(lib)
+
+gemspec
+
+gem "rake", "~> 0.9.2"
+gem "rspec", "~> 2.6.0"
+gem "cucumber", "~> 1.1.0"
+gem "aruba", "~> 0.4.6"
+
+gem "activesupport", "~> 3.0.10"
+gem "actionpack", "~> 3.0.10"
+
+gem "ruby-debug", "~> 0.10.4", :platforms => :mri_18
+gem "ruby-debug19", "~> 0.11.6", :platforms => :mri_19
View
22 Gemfile.rails2
@@ -1,22 +0,0 @@
-source "http://rubygems.org"
-
-lib = File.expand_path('../lib', __FILE__)
-$:.unshift lib unless $:.include?(lib)
-
-gemspec
-
-gem "rake", "0.8.7"
-gem "aruba", "~> 0.2.3"
-gem "capybara", "~> 0.3.9"
-gem "cucumber", "~> 0.9.3"
-gem "cucumber-rails", "~> 0.3.2"
-gem "database_cleaner", "~> 0.5.2"
-gem "rails", "~> 2.3.10"
-gem "rspec", "~> 2.0.1"
-gem "sqlite3-ruby", "~> 1.3.0"
-gem "will_paginate", "~> 2.3.14"
-
-gem "ruby-debug", "~> 0.10.3", :platforms => :mri_18
-gem "ruby-debug19", "~> 0.11.6", :platforms => :mri_19
-
-gem "test-unit", "1.2.3", :platforms => :ruby_19
View
22 Gemfile.rails3
@@ -1,22 +0,0 @@
-source "http://rubygems.org"
-
-lib = File.expand_path('../lib', __FILE__)
-$:.unshift lib unless $:.include?(lib)
-
-gemspec
-
-gem "rake", "0.8.7"
-gem "aruba", "~> 0.2.3"
-gem "capybara", "~> 0.4.0"
-gem "cucumber", "~> 0.9.3"
-gem "cucumber-rails", "~> 0.3.2"
-gem "database_cleaner", "~> 0.6.0"
-gem "rails", "~> 3.0.1"
-gem "rspec-rails", "~> 2.0.1"
-gem "sqlite3-ruby", "~> 1.3.0"
-gem "will_paginate", "~> 3.0.2"
-
-gem "ruby-debug", "~> 0.10.3", :platforms => :mri_18
-gem "ruby-debug19", "~> 0.11.6", :platforms => :mri_19
-
-gem "test-unit", "1.2.3", :platforms => :ruby_19
View
141 Rakefile
@@ -1,3 +1,6 @@
+require 'bundler'
+Bundler.setup
+
begin
require 'rspec/core/rake_task'
require 'cucumber/rake/task'
@@ -7,87 +10,67 @@ begin
t.rspec_opts = %w(--format=progress --color)
end
- Cucumber::Rake::Task.new(:cucumber) do |t|
+ Cucumber::Rake::Task.new do |t|
t.cucumber_opts = %w{--format progress}
end
-
- Cucumber::Rake::Task.new('cucumber:rails2') do |t|
- t.cucumber_opts = %w{--format progress --tags ~@rails3}
- end
-
- Cucumber::Rake::Task.new('cucumber:rails3') do |t|
- t.cucumber_opts = %w{--format progress --tags ~@rails2}
- end
rescue LoadError
puts "Warning: RSpec or Cucumber is not installed"
end
task :default => [:spec, :cucumber]
-task :rails2 => [:spec, 'cucumber:rails2']
-task :rails3 => [:spec, 'cucumber:rails3']
-
-namespace :generate do
- namespace :rails3 do
- desc 'Generate Rails 3 app for integration testing'
- task :app do
- unless File.directory? './tmp/example_app'
- template_dir = '../../templates/rails3/'
- system 'rails new ./tmp/example_app --skip-gemfile'
+directory "tmp/example_app"
- Dir.chdir("./tmp/example_app/") do
- system 'rails generate cucumber:install --capybara'
-
- ['Gemfile',
- 'features/step_definitions/custom_steps.rb'].each do |file|
- system "cp #{template_dir + file} ./#{file}"
- end
+module BasicAssumptionRakeUtils
+ TEMPLATE_DIR = 'templates/rails/'
+end
- system "bundle install"
- end
- end
+file "tmp/example_app/Gemfile" => "tmp/example_app" do
+ open("tmp/example_app/Gemfile", "w") do |gemfile|
+ open("#{BasicAssumptionRakeUtils::TEMPLATE_DIR}Gemfile") do |template|
+ gemfile << template.read
end
+ end
+end
- desc 'Generate scaffolds, etc'
- task :custom => ['generate:rails3:app'] do
- Dir.chdir("./tmp/example_app/") do
- system "rake rails:template LOCATION='../../templates/generate_custom.rb'"
- end
+namespace :example_app do
+ task :bundle => "tmp/example_app/Gemfile" do
+ Bundler.with_clean_env do
+ system 'cd ./tmp/example_app/ && bundle'
end
end
- namespace :rails2 do
- desc 'Generate Rails 2.3 app for integration testing'
- task :app do
- unless File.directory? './tmp/example_app'
- template_dir = '../../templates/rails2/'
-
- system 'rails ./tmp/example_app'
-
- Dir.chdir("./tmp/example_app/") do
- system 'script/generate cucumber'
-
- ['Gemfile',
- 'config/boot.rb',
- 'config/preinitializer.rb',
- 'features/step_definitions/custom_steps.rb'].each do |file|
- system "cp #{template_dir + file} ./#{file}"
- end
-
- system "bundle install"
- end
+ task :generate => "example_app:bundle" do
+ Bundler.with_clean_env do
+ Dir.chdir("./tmp/example_app/") do
+ system 'bundle exec rails new ./ -JSGT --skip-gemfile --skip-bundle'
+ system 'bundle exec rails generate cucumber:install --capybara'
+ system 'bundle exec rails generate cucumber_rails_training_wheels:install'
end
end
+ end
- desc 'Generate scaffolds, etc'
- task :custom => ['generate:rails2:app'] do
+ task :customize => 'example_app:generate' do
+ Bundler.with_clean_env do
Dir.chdir("./tmp/example_app/") do
- system "rake rails:template LOCATION='../../templates/generate_custom.rb'"
+ system "bundle exec rake rails:template LOCATION='../../templates/generate_custom.rb'"
end
+
+ custom_steps = 'features/step_definitions/custom_steps.rb'
+ system "cp #{BasicAssumptionRakeUtils::TEMPLATE_DIR}#{custom_steps} tmp/example_app/#{custom_steps}"
end
end
end
+desc 'Generate customized Rails 3 app for integration testing'
+task :init => [:clobber, 'example_app:customize']
+
+desc 'Remove all generated test files'
+task :clobber do
+ rm_rf './tmp'
+ rm_rf './pkg'
+end
+
namespace :gem do
desc 'Builds the gem from the current gemspec'
task :build do
@@ -97,23 +80,9 @@ namespace :gem do
end
end
-namespace :bundle do
- namespace :install do
- desc "Installs the dependencies listed in Gemfile.rails2"
- task :rails2 do
- system 'cp Gemfile.rails2 Gemfile && bundle install'
- end
-
- desc "Installs the dependencies listed in Gemfile.rails3"
- task :rails3 do
- system 'cp Gemfile.rails3 Gemfile && bundle install'
- end
- end
-end
-
namespace :rvm do
desc "Creates a gemset and outputs the command to use it"
- task :gemset do
+ task :gemset => "tmp/example_app" do
if `which rvm` =~ /\w+/
system "rvm gemset create basic_assumption"
@@ -128,31 +97,3 @@ namespace :rvm do
end
end
-namespace :setup do
- desc 'Sets up the test environment for Rails 2.3'
- task :rails2 => ['bundle:install:rails2', 'generate:rails2:custom']
-
- desc 'Sets up the test environment for Rails 3'
- task :rails3 => ['bundle:install:rails3', 'generate:rails3:custom']
-end
-
-namespace :init do
- desc 'Sets up and runs the spec and cuke suites using Rails 2.3'
- task :rails2 => [:clobber, 'setup:rails2']
-
- desc 'Sets up and runs the spec and cuke suites using Rails 3'
- task :rails3 => [:clobber, 'setup:rails3']
-end
-
-namespace :clobber do
- desc 'Remove generated Rails app'
- task :app do
- rm_rf './tmp/example_app'
- end
-end
-
-desc 'Remove generated code'
-task :clobber do
- rm_rf './tmp'
- rm_rf './pkg'
-end
View
2 features/rails_controllers_assume_find_by_default.feature
@@ -19,7 +19,7 @@ Feature: Rails Controllers Assume Find By Default
When I view the widget
Then I should see "foobar"
"""
- When I run "cucumber features/widget_is_viewed_by_visitor.feature"
+ When I run `bundle exec cucumber features/widget_is_viewed_by_visitor.feature` with a clean Bundler environment
Then the output should contain:
"""
1 scenario (1 passed)
View
2 features/rails_controllers_can_make_assumptions.feature
@@ -19,7 +19,7 @@ Feature: Rails Controllers Can Make Assumptions
When I view the widget
Then I should see "foobar"
"""
- When I run "cucumber features/widget_is_viewed_by_visitor.feature"
+ When I run `cucumber features/widget_is_viewed_by_visitor.feature` with a clean Bundler environment
Then the output should contain:
"""
1 scenario (1 passed)
View
2 features/rails_controllers_inherit_assumptions.feature
@@ -25,7 +25,7 @@ Feature: Rails Controllers Inherit Assumptions
When I view the derived widget
Then I should see "foobar"
"""
- When I run "cucumber features/derived_widget_is_viewed_by_visitor.feature"
+ When I run `cucumber features/derived_widget_is_viewed_by_visitor.feature` with a clean Bundler environment
Then the output should contain:
"""
1 scenario (1 passed)
View
4 features/restful_rails_create_action_is_correct.feature
@@ -15,7 +15,7 @@ Feature: Restful Rails Create Action Is Correct
"""
And a file named "app/views/widgets/new.html.erb" with:
"""
- <% form_for widget do |form| %>
+ <%= form_for widget do |form| %>
<%= form.label :name, "Name" %>
<%= form.text_field :name %>
<%= submit_tag "Create" %>
@@ -36,7 +36,7 @@ Feature: Restful Rails Create Action Is Correct
And I press "Create"
Then I should see "created"
"""
- When I run "cucumber features/widget_is_created_by_visitor.feature"
+ When I run `cucumber features/widget_is_created_by_visitor.feature` with a clean Bundler environment
Then the output should contain:
"""
1 scenario (1 passed)
View
4 features/restful_rails_destroy_action_is_correct.feature
@@ -25,7 +25,7 @@ Feature: Restful Rails Destroy Action Is Correct
Given a file named "app/views/widgets/show.html.erb" with:
"""
<%= widget.name unless widget.frozen? %>
- <% form_for widget do |form| %>
+ <%= form_for widget do |form| %>
<%= hidden_field_tag '_method', 'delete' %>
<%= submit_tag "Delete" %>
<% end %>
@@ -41,7 +41,7 @@ Feature: Restful Rails Destroy Action Is Correct
Then I should not see "sprocket"
And I should see "spacely"
"""
- When I run "cucumber features/widget_is_deleted_by_visitor.feature"
+ When I run `cucumber features/widget_is_deleted_by_visitor.feature` with a clean Bundler environment
Then the output should contain:
"""
1 scenario (1 passed)
View
2 features/restful_rails_edit_action_is_correct.feature
@@ -20,7 +20,7 @@ Feature: Restful Rails Edit Action Is Correct
When I edit the widget
Then I should see "Editing sprocket"
"""
- When I run "cucumber features/widget_is_edited_by_visitor.feature"
+ When I run `cucumber features/widget_is_edited_by_visitor.feature` with a clean Bundler environment
Then the output should contain:
"""
1 scenario (1 passed)
View
6 features/restful_rails_index_action_is_correct.feature
@@ -35,7 +35,7 @@ Feature: Restful Rails Index Action Is Correct
And I should see "George"
And I should see "Ringo"
"""
- When I run "cucumber features/all_widgets_are_viewed_by_visitor.feature"
+ When I run `cucumber features/all_widgets_are_viewed_by_visitor.feature` with a clean Bundler environment
Then the output should contain:
"""
1 scenario (1 passed)
@@ -70,7 +70,7 @@ Feature: Restful Rails Index Action Is Correct
And I should see "Theodore"
And I should see "New widget"
"""
- When I run "cucumber features/all_widgets_and_a_new_widget_are_viewed_by_visitor.feature"
+ When I run `cucumber features/all_widgets_and_a_new_widget_are_viewed_by_visitor.feature` with a clean Bundler environment
Then the output should contain:
"""
1 scenario (1 passed)
@@ -104,7 +104,7 @@ Feature: Restful Rails Index Action Is Correct
And I should see "Theodore"
And I should see "sprocket"
"""
- When I run "cucumber features/all_widgets_and_a_singular_widget_are_viewed_by_visitor.feature"
+ When I run `cucumber features/all_widgets_and_a_singular_widget_are_viewed_by_visitor.feature` with a clean Bundler environment
Then the output should contain:
"""
1 scenario (1 passed)
View
4 features/restful_rails_index_action_with_pagination_is_correct.feature
@@ -43,7 +43,7 @@ Feature: Restful Rails Index Action With Pagination Is Correct
And I should not see "Jason"
And I should not see "Damian"
"""
- When I run "cucumber features/first_half_of_widgets_are_viewed_by_visitor.feature"
+ When I run `cucumber features/first_half_of_widgets_are_viewed_by_visitor.feature` with a clean Bundler environment
Then the output should contain:
"""
1 scenario (1 passed)
@@ -75,7 +75,7 @@ Feature: Restful Rails Index Action With Pagination Is Correct
And I should not see "Jason"
And I should not see "Damian"
"""
- When I run "cucumber features/second_half_of_widgets_are_viewed_by_visitor.feature"
+ When I run `cucumber features/second_half_of_widgets_are_viewed_by_visitor.feature` with a clean Bundler environment
Then the output should contain:
"""
1 scenario (1 passed)
View
2 features/restful_rails_new_action_is_correct.feature
@@ -21,7 +21,7 @@ Feature: Restful Rails New Action Is Correct
When I go to the new widget page
Then I should see "Widget is new"
"""
- When I run "cucumber features/widget_is_newed_by_visitor.feature"
+ When I run `cucumber features/widget_is_newed_by_visitor.feature` with a clean Bundler environment
Then the output should contain:
"""
1 scenario (1 passed)
View
2 features/restful_rails_show_action_is_correct.feature
@@ -20,7 +20,7 @@ Feature: Restful Rails Show Action Is Correct
When I view the widget
Then I should see "sprocket"
"""
- When I run "cucumber features/widget_is_viewed_by_visitor.feature"
+ When I run `cucumber features/widget_is_viewed_by_visitor.feature` with a clean Bundler environment
Then the output should contain:
"""
1 scenario (1 passed)
View
4 features/restful_rails_update_action_is_correct.feature
@@ -15,7 +15,7 @@ Feature: Restful Rails Update Action Is Correct
"""
And a file named "app/views/widgets/edit.html.erb" with:
"""
- <% form_for widget do |form| %>
+ <%= form_for widget do |form| %>
<%= form.label :name, "Name" %>
<%= form.text_field :name %>
<%= submit_tag "Update" %>
@@ -35,7 +35,7 @@ Feature: Restful Rails Update Action Is Correct
And I press "Update"
Then I should see "after"
"""
- When I run "cucumber features/widget_is_updated_by_visitor.feature"
+ When I run `cucumber features/widget_is_updated_by_visitor.feature` with a clean Bundler environment
Then the output should contain:
"""
1 scenario (1 passed)
View
2 features/rspec_matcher_for_assume.feature
@@ -21,7 +21,7 @@ Feature: RSpec Matcher For Assume
it { should_not assume(:sprocket) }
end
"""
- When I run "bundle exec rspec spec/controllers/widgets_controller_spec.rb"
+ When I run `bundle exec rspec spec/controllers/widgets_controller_spec.rb` with a clean Bundler environment
Then the output should contain:
"""
2 examples, 0 failures
View
6 features/step_definitions/custom_aruba.rb
@@ -0,0 +1,6 @@
+require 'aruba/api'
+
+When /^I run `([^`]*)` with a clean Bundler environment$/ do |cmd|
+ Bundler.with_clean_env { run_simple(unescape(cmd), false) }
+end
+
View
4 features/support/env.rb
@@ -3,7 +3,7 @@
require 'bundler'
Bundler.setup
-require 'aruba'
+require 'aruba/cucumber'
def aruba_path(file_or_dir)
File.expand_path("../../../#{file_or_dir.sub('example_app','aruba')}", __FILE__)
@@ -27,4 +27,6 @@ def write_symlink(file_or_dir)
Dir['tmp/example_app/*'].each do |file_or_dir|
write_symlink(file_or_dir)
end
+
+ @aruba_timeout_seconds = 20
end
View
18 templates/rails/Gemfile
@@ -0,0 +1,18 @@
+source "http://rubygems.org"
+
+lib = File.expand_path('../../../lib', __FILE__)
+$:.unshift lib unless $:.include?(lib)
+
+gemspec :path => "../../"
+
+gem "rails", "~> 3.1.1"
+gem "sqlite3-ruby", "~> 1.3.3"
+gem "will_paginate", "~> 3.0.2"
+
+group :test do
+ gem "capybara", "~> 1.1.1"
+ gem "cucumber", "~> 1.1.0"
+ gem "cucumber-rails", "~> 1.1.1"
+ gem "database_cleaner", "~> 0.6.7"
+ gem "cucumber-rails-training-wheels"
+end
View
0 ...features/step_definitions/custom_steps.rb → ...features/step_definitions/custom_steps.rb
File renamed without changes.
View
15 templates/rails2/Gemfile
@@ -1,15 +0,0 @@
-lib = File.expand_path('../../../lib', __FILE__)
-$:.unshift lib unless $:.include?(lib)
-
-gemspec :path => '../../'
-
-gem "rails", "~> 2.3.10"
-gem "sqlite3-ruby", "~> 1.3.0"
-gem "will_paginate", "~> 2.3.14"
-
-group :test do
- gem "capybara", "~> 0.3.9"
- gem "cucumber", "~> 0.9.3"
- gem "cucumber-rails", "~> 0.3.2"
- gem "database_cleaner", "~> 0.5.2"
-end
View
125 templates/rails2/config/boot.rb
@@ -1,125 +0,0 @@
-# Don't change this file!
-# Configure your app in config/environment.rb and config/environments/*.rb
-
-RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
-
-module Rails
- class << self
- def boot!
- unless booted?
- preinitialize
- pick_boot.run
- end
- end
-
- def booted?
- defined? Rails::Initializer
- end
-
- def pick_boot
- (vendor_rails? ? VendorBoot : GemBoot).new
- end
-
- def vendor_rails?
- File.exist?("#{RAILS_ROOT}/vendor/rails")
- end
-
- def preinitialize
- load(preinitializer_path) if File.exist?(preinitializer_path)
- end
-
- def preinitializer_path
- "#{RAILS_ROOT}/config/preinitializer.rb"
- end
- end
-
- class Boot
- def run
- load_initializer
- Rails::Initializer.run(:set_load_path)
- end
- end
-
- class VendorBoot < Boot
- def load_initializer
- require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
- Rails::Initializer.run(:install_gem_spec_stubs)
- Rails::GemDependency.add_frozen_gem_path
- end
- end
-
- class GemBoot < Boot
- def load_initializer
- self.class.load_rubygems
- load_rails_gem
- require 'initializer'
- end
-
- def load_rails_gem
- if version = self.class.gem_version
- gem 'rails', version
- else
- gem 'rails'
- end
- rescue Gem::LoadError => load_error
- $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
- exit 1
- end
-
- class << self
- def rubygems_version
- Gem::RubyGemsVersion rescue nil
- end
-
- def gem_version
- if defined? RAILS_GEM_VERSION
- RAILS_GEM_VERSION
- elsif ENV.include?('RAILS_GEM_VERSION')
- ENV['RAILS_GEM_VERSION']
- else
- parse_gem_version(read_environment_rb)
- end
- end
-
- def load_rubygems
- min_version = '1.3.2'
- require 'rubygems'
- unless rubygems_version >= min_version
- $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
- exit 1
- end
-
- rescue LoadError
- $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
- exit 1
- end
-
- def parse_gem_version(text)
- $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
- end
-
- private
- def read_environment_rb
- File.read("#{RAILS_ROOT}/config/environment.rb")
- end
- end
- end
-end
-
-# All that for this:
-
-class Rails::Boot
- def run
- load_initializer
-
- Rails::Initializer.class_eval do
- def load_gems
- @bundler_loaded ||= Bundler.require :default, Rails.env
- end
- end
-
- Rails::Initializer.run(:set_load_path)
- end
-end
-
-Rails.boot!
View
20 templates/rails2/config/preinitializer.rb
@@ -1,20 +0,0 @@
-begin
- require "rubygems"
- require "bundler"
-rescue LoadError
- raise "Could not load the bundler gem. Install it with `gem install bundler`."
-end
-
-if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.24")
- raise RuntimeError, "Your bundler version is too old for Rails 2.3." +
- "Run `gem install bundler` to upgrade."
-end
-
-begin
- # Set up load paths for all bundled gems
- ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__)
- Bundler.setup
-rescue Bundler::GemNotFound
- raise RuntimeError, "Bundler couldn't find some gems." +
- "Did you run `bundle install`?"
-end
View
33 templates/rails2/features/step_definitions/custom_steps.rb
@@ -1,33 +0,0 @@
-Given /^a (?:|derived )widget named "(.+)"$/ do |widget_name|
- @widget = Widget.create!(:name => widget_name)
-end
-
-Given /^the following widgets:$/ do |table|
- table.hashes.each do |widget_hash|
- Widget.create!(widget_hash)
- end
-end
-
-When /^I view the (derived )?widget$/ do |derived|
- if derived
- visit derived_widget_path(@widget)
- else
- visit widget_path(@widget)
- end
-end
-
-When /^I edit the widget$/ do
- visit edit_widget_path(@widget)
-end
-
-When /^I view all widgets$/ do
- visit widgets_path
-end
-
-When /^I view all widgets and there is an id in params$/ do
- visit widgets_path(:id => @widget.id)
-end
-
-When /^I view page (\d+) of all widgets(?: with (\d+) per page)?$/ do |page, per_page|
- visit widgets_path(:page => page, :per_page => per_page)
-end
View
16 templates/rails3/Gemfile
@@ -1,16 +0,0 @@
-lib = File.expand_path('../../../lib', __FILE__)
-$:.unshift lib unless $:.include?(lib)
-
-gemspec :path => "../../"
-
-gem "rails", "~> 3.0.1"
-gem "sqlite3-ruby", "~> 1.3.0"
-gem "will_paginate", "~> 3.0.pre2"
-
-group :test do
- gem 'rspec-rails', "~> 2.0.1"
- gem "capybara", "~> 0.4.0"
- gem "cucumber", "~> 0.9.3"
- gem "cucumber-rails", "~> 0.3.2"
- gem "database_cleaner", "~> 0.6.0"
-end

0 comments on commit dfb3cb0

Please sign in to comment.