cucumber-rails2 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/.gitignore +4 -0
  2. data/HACKING.rdoc +24 -0
  3. data/History.txt +145 -0
  4. data/LICENSE +22 -0
  5. data/README.rdoc +70 -0
  6. data/Rakefile +24 -0
  7. data/VERSION +1 -0
  8. data/config/.gitignore +1 -0
  9. data/cucumber-rails2.gemspec +111 -0
  10. data/dev_tasks/cucumber.rake +5 -0
  11. data/dev_tasks/rspec.rake +13 -0
  12. data/features/rails2.feature +64 -0
  13. data/features/rails3.feature +97 -0
  14. data/features/rerun_profile.feature +39 -0
  15. data/features/step_definitions/cucumber_rails_steps.rb +35 -0
  16. data/features/support/env.rb +4 -0
  17. data/features/support/matchers/files.rb +17 -0
  18. data/generators/cucumber/USAGE +13 -0
  19. data/generators/cucumber/cucumber_generator.rb +88 -0
  20. data/generators/feature/USAGE +12 -0
  21. data/generators/feature/feature_generator.rb +47 -0
  22. data/lib/cucumber/rails/action_controller.rb +65 -0
  23. data/lib/cucumber/rails/active_record.rb +34 -0
  24. data/lib/cucumber/rails/capybara_javascript_emulation.rb +81 -0
  25. data/lib/cucumber/rails/rspec.rb +22 -0
  26. data/lib/cucumber/rails/test_unit.rb +7 -0
  27. data/lib/cucumber/rails/world.rb +48 -0
  28. data/lib/cucumber/web/tableish.rb +118 -0
  29. data/lib/generators/cucumber/feature/USAGE +16 -0
  30. data/lib/generators/cucumber/feature/feature_base.rb +29 -0
  31. data/lib/generators/cucumber/feature/feature_generator.rb +37 -0
  32. data/lib/generators/cucumber/feature/named_arg.rb +17 -0
  33. data/lib/generators/cucumber/install/USAGE +15 -0
  34. data/lib/generators/cucumber/install/install_base.rb +202 -0
  35. data/lib/generators/cucumber/install/install_generator.rb +64 -0
  36. data/spec/cucumber/web/tableish_spec.rb +192 -0
  37. data/spec/generators/cucumber/install/install_base_spec.rb +84 -0
  38. data/spec/spec.opts +2 -0
  39. data/spec/spec_helper.rb +6 -0
  40. data/templates/feature/feature.erb +63 -0
  41. data/templates/feature/steps.erb +14 -0
  42. data/templates/install/config/cucumber.yml.erb +8 -0
  43. data/templates/install/environments/cucumber.rb.erb +37 -0
  44. data/templates/install/script/cucumber +10 -0
  45. data/templates/install/step_definitions/capybara_steps.rb.erb +214 -0
  46. data/templates/install/step_definitions/web_steps_cs.rb.erb +136 -0
  47. data/templates/install/step_definitions/web_steps_da.rb.erb +114 -0
  48. data/templates/install/step_definitions/web_steps_de.rb.erb +136 -0
  49. data/templates/install/step_definitions/web_steps_es.rb.erb +136 -0
  50. data/templates/install/step_definitions/web_steps_ja.rb.erb +139 -0
  51. data/templates/install/step_definitions/web_steps_ko.rb.erb +141 -0
  52. data/templates/install/step_definitions/web_steps_no.rb.erb +114 -0
  53. data/templates/install/step_definitions/web_steps_pt-BR.rb.erb +140 -0
  54. data/templates/install/step_definitions/webrat_steps.rb.erb +276 -0
  55. data/templates/install/support/_rails_each_run.rb.erb +35 -0
  56. data/templates/install/support/_rails_prefork.rb.erb +12 -0
  57. data/templates/install/support/capybara.rb +9 -0
  58. data/templates/install/support/edit_warning.txt +5 -0
  59. data/templates/install/support/paths.rb +33 -0
  60. data/templates/install/support/rails.rb.erb +4 -0
  61. data/templates/install/support/rails_spork.rb.erb +13 -0
  62. data/templates/install/support/webrat.rb +8 -0
  63. data/templates/install/tasks/cucumber.rake.erb +48 -0
  64. metadata +143 -0
@@ -0,0 +1,97 @@
1
+ @announce-cmd
2
+ @announce @puts
3
+ Feature: Rails 3
4
+ In order to take over the world
5
+ Cucumber-Rails should work on major versions
6
+ of Rails2 and Ruby, with Capybara, Spork and DatabaseCleaner
7
+
8
+ Scenario: Install Cucumber-Rails
9
+ Given I am using rvm "ruby-1.8.7-p249"
10
+ And I am using rvm gemset "cucumber-rails-3.0.0.beta" with Gemfile:
11
+ """
12
+ source :gemcutter
13
+ gem 'rails', '3.0.0.beta'
14
+ gem 'sqlite3-ruby', '1.2.5'
15
+ gem 'capybara', '0.3.8'
16
+ """
17
+ When I successfully run "rails rails-3-app"
18
+ Then it should pass with:
19
+ """
20
+ README
21
+ """
22
+ And I cd to "rails-3-app"
23
+ And I symlink "../../.." to "vendor/plugins/cucumber-rails"
24
+ When I successfully run "rails generate cucumber:install --capybara"
25
+ Then the following files should exist:
26
+ | config/cucumber.yml |
27
+ | script/cucumber |
28
+ | features/step_definitions/web_steps.rb |
29
+ | features/support/env.rb |
30
+ | features/support/paths.rb |
31
+ | lib/tasks/cucumber.rake |
32
+ And the file "features/support/env.rb" should contain "require 'cucumber/rails/world'"
33
+ And the file "features/support/env.rb" should contain "require 'capybara/rails'"
34
+
35
+ Scenario Outline: Run Cucumber
36
+ Given I am using rvm "<ruby_version>"
37
+ And I am using rvm gemset "cucumber-rails-3.0.0.beta-gemset-<gemset>" with Gemfile:
38
+ """
39
+ source :gemcutter
40
+ gem 'rails', '3.0.0.beta'
41
+ gem 'sqlite3-ruby', '1.2.5'
42
+ gem 'capybara', '0.3.8'
43
+ gem 'gherkin', '1.0.30'
44
+ gem 'term-ansicolor', '1.0.4'
45
+ gem 'diff-lcs', '1.1.2'
46
+ gem 'rspec-rails', '<rspec_version>'
47
+ """
48
+ And I successfully run "rails rails-3-app"
49
+ And I cd to "rails-3-app"
50
+ And I symlink "../../.." to "vendor/plugins/cucumber-rails"
51
+ And I append to "Gemfile" with:
52
+ """
53
+ gem 'capybara', '0.3.8'
54
+ gem 'cucumber', :path => '../../../../cucumber'
55
+
56
+ """
57
+ And I successfully run "rails generate cucumber:install --capybara"
58
+ And I successfully run "rails generate cucumber:feature post title:string body:text published:boolean"
59
+ And I successfully run "rails generate scaffold post title:string body:text published:boolean"
60
+ And I successfully run "rails generate scaffold cukes name:string"
61
+ And I write to "app/controllers/cukes_controller.rb" with:
62
+ """
63
+ class CukesController < ApplicationController
64
+ def index
65
+ redirect_to cuke_path(10, :overwrite_params => {:name => 'cucumber', :what => 'vegetable'})
66
+ end
67
+
68
+ def show
69
+ render :text => "Cuke #{params[:id]}"
70
+ end
71
+ end
72
+ """
73
+ And I write to "features/tests.feature" with:
74
+ """
75
+ Feature: Tests
76
+ Scenario: Tests
77
+ When I go to the cukes page
78
+ Then I should have the following query string:
79
+ |name|cucumber|
80
+ |what|vegetable|
81
+ |controller|cukes|
82
+ |action|index|
83
+ And I should see "Cuke 10"
84
+ """
85
+ And I successfully run "bundle lock"
86
+ And I successfully run "rake db:migrate"
87
+ And I successfully run "rake cucumber"
88
+ Then it should pass with:
89
+ """
90
+ 3 scenarios (3 passed)
91
+ 14 steps (14 passed)
92
+ """
93
+
94
+ Examples:
95
+ | ruby_version | rspec_version | gemset |
96
+ | ruby-1.8.7-p249 | 1.3.2 | 1 |
97
+ | ruby-1.9.1-p378 | 2.0.0.beta.10 | 2 |
@@ -0,0 +1,39 @@
1
+ @announce
2
+ Feature: Rerun profile
3
+ In order to concentrate on failing features
4
+ As a Rails developer working with Cucumber
5
+ I want to rerun only failing features
6
+
7
+ Scenario: Rerun
8
+ Given I have created a new Rails 3 app "rails-3-app" with cucumber-rails support
9
+ And a file named "rerun.txt" with:
10
+ """
11
+ features/rerun_test.feature:2
12
+ """
13
+ And a file named "features/rerun_test.feature" with:
14
+ """
15
+ Feature: Rerun test
16
+ Scenario: failing before
17
+ Given fixed now
18
+
19
+ Scenario: always passing
20
+ Given passing
21
+ """
22
+ And a file named "features/step_definitions/rerun_steps.rb" with:
23
+ """
24
+ Given /fixed now/ do
25
+ puts "All fixed now"
26
+ end
27
+
28
+ Given /passing/ do
29
+ puts "I've always been passing"
30
+ end
31
+ """
32
+ When I successfully run "ruby script/cucumber -p rerun"
33
+ Then it should pass with:
34
+ """
35
+ 1 scenario (1 passed)
36
+ 1 step (1 passed)
37
+ """
38
+ And the file "rerun.txt" should not contain "features/rerun_test.feature:2"
39
+
@@ -0,0 +1,35 @@
1
+ Given /^I symlink "([^"]*)" to "([^"]*)"$/ do |source, target|
2
+ source = File.expand_path(source, __FILE__)
3
+ in_current_dir do
4
+ target = File.expand_path(target)
5
+ FileUtils.ln_s(source, target)
6
+ end
7
+ end
8
+
9
+ Given /^I have created a new Rails 3 app "([^"]*)" with cucumber\-rails support$/ do |app_name|
10
+ steps %Q{
11
+ Given I am using rvm "ruby-1.8.7-p249"
12
+ And I am using rvm gemset "cucumber-rails-3.0.0.beta-gemset-1" with Gemfile:
13
+ """
14
+ gem 'rails', '3.0.0.beta'
15
+ gem 'sqlite3-ruby', '1.2.5'
16
+ gem 'capybara', '0.3.8'
17
+ """
18
+ When I successfully run "rails rails-3-app"
19
+ Then it should pass with:
20
+ """
21
+ README
22
+ """
23
+ And I cd to "#{app_name}"
24
+ And I symlink "../../.." to "vendor/plugins/cucumber-rails"
25
+ And I append to "Gemfile" with:
26
+ """
27
+ gem 'capybara', '0.3.8'
28
+ gem 'cucumber', :path => '../../../../cucumber'
29
+
30
+ """
31
+ And I successfully run "rails generate cucumber:install --capybara"
32
+ And I successfully run "bundle lock"
33
+ And I successfully run "rake db:migrate"
34
+ }
35
+ end
@@ -0,0 +1,4 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'rubygems'
3
+ require 'rspec/expectations'
4
+ require 'aruba'
@@ -0,0 +1,17 @@
1
+ RSpec::Matchers.define :have_files do |expected_files|
2
+ match do |rails_app|
3
+ actual_files = rails_app.files
4
+ @missing_files = expected_files - actual_files
5
+ @missing_files.empty?
6
+ end
7
+
8
+ failure_message_for_should do |expected_files|
9
+ "Rails app was missing these files:\n" + @missing_files.map { |file| " #{file}" }.join("\n")
10
+ end
11
+ end
12
+
13
+ RSpec::Matchers.define :have_contents do |contents|
14
+ match do |file|
15
+ file.read.include?(contents)
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ Description:
2
+ Sets up Cucumber in your Rails project. After running this generator you will
3
+ get a new rake task called features.
4
+
5
+ This also generates the necessary files in the features directory.
6
+
7
+ Also see the feature generator
8
+
9
+ Examples:
10
+ `./script/generate cucumber`
11
+
12
+ You can also provide a language argument for localized webrat_steps:
13
+ `./script/generate cucumber de`
@@ -0,0 +1,88 @@
1
+ require 'rbconfig'
2
+ require File.expand_path(File.join(File.dirname(__FILE__), '../../lib/generators/cucumber/install/install_base'))
3
+
4
+ # This generator bootstraps a Rails project for use with Cucumber
5
+ class CucumberGenerator < Rails::Generator::Base
6
+
7
+ include Cucumber::Generators::InstallBase
8
+
9
+ attr_accessor :driver
10
+ attr_accessor :framework
11
+ attr_reader :language, :template_dir
12
+
13
+ def initialize(runtime_args, runtime_options = {})
14
+ super
15
+ @language = @args.empty? ? 'en' : @args.first
16
+ end
17
+
18
+ def manifest
19
+ record do |m|
20
+ check_upgrade_limitations
21
+ create_templates(m, true)
22
+ create_scripts(m, true)
23
+ create_step_definitions(m, true)
24
+ create_feature_support(m, true)
25
+ create_tasks(m, true)
26
+ create_database(m, true)
27
+ end
28
+ end
29
+
30
+ def framework
31
+ options[:framework] ||= detect_current_framework || detect_default_framework
32
+ end
33
+
34
+ def driver
35
+ options[:driver] ||= detect_current_driver || detect_default_driver
36
+ end
37
+
38
+ def cucumber_rails_env
39
+ 'cucumber'
40
+ end
41
+
42
+ def self.gem_root
43
+ File.expand_path('../../../', __FILE__)
44
+ end
45
+
46
+ def self.source_root
47
+ File.join(gem_root, 'templates', 'install')
48
+ end
49
+
50
+ def source_root
51
+ self.class.source_root
52
+ end
53
+
54
+ private
55
+
56
+ def banner
57
+ "Usage: #{$0} cucumber (language)"
58
+ end
59
+
60
+ def after_generate
61
+ print_instructions
62
+ end
63
+
64
+ def add_options!(opt)
65
+ opt.separator ''
66
+ opt.separator 'Options:'
67
+ opt.on('--webrat', 'Setup cucumber for use with webrat') do
68
+ options[:driver] = :webrat
69
+ end
70
+
71
+ opt.on('--capybara', 'Setup cucumber for use with capybara') do
72
+ options[:driver] = :capybara
73
+ end
74
+
75
+ opt.on('--rspec', "Setup cucumber for use with RSpec") do
76
+ options[:framework] = :rspec
77
+ end
78
+
79
+ opt.on('--testunit', "Setup cucumber for use with test/unit") do
80
+ options[:framework] = :testunit
81
+ end
82
+
83
+ opt.on('--spork', 'Setup cucumber for use with Spork') do
84
+ options[:spork] = true
85
+ end
86
+ end
87
+
88
+ end
@@ -0,0 +1,12 @@
1
+ Description:
2
+ Generates a skeleton for a new feature. Both a simple .feature file and
3
+ a steps.rb file is generated. This generator should be used with moderation.
4
+ See http://github.com/aslakhellesoy/cucumber/wikis/feature-coupled-steps-antipattern
5
+ for details about the dangers involved.
6
+
7
+ This generator can take an optional list of attribute pairs similar to Rails'
8
+ built-in resource generator.
9
+
10
+ Examples:
11
+ `./script/generate feature post` # no attributes
12
+ `./script/generate feature post title:string body:text published:boolean`
@@ -0,0 +1,47 @@
1
+ require File.join(File.dirname(__FILE__), '../../lib/generators/cucumber/feature/named_arg')
2
+ require File.join(File.dirname(__FILE__), '../../lib/generators/cucumber/feature/feature_base')
3
+
4
+ # This generator generates a baic feature.
5
+ class FeatureGenerator < Rails::Generator::NamedBase
6
+
7
+ include Cucumber::Generators::FeatureBase
8
+
9
+ def manifest
10
+ record do |m|
11
+ create_directory(m, true)
12
+ create_feature_file(m)
13
+ create_steps_file(m)
14
+ create_support_file(m)
15
+ end
16
+ end
17
+
18
+ def self.gem_root
19
+ File.expand_path('../../../', __FILE__)
20
+ end
21
+
22
+ def self.source_root
23
+ File.join(gem_root, 'templates', 'feature')
24
+ end
25
+
26
+ def source_root
27
+ self.class.source_root
28
+ end
29
+
30
+ def named_args
31
+ args.map { |arg| NamedArg.new(arg) }
32
+ end
33
+
34
+ private
35
+
36
+ def banner
37
+ "Usage: #{$0} feature ModelName [field:type, field:type]"
38
+ end
39
+
40
+ def add_options!(opt)
41
+ opt.separator ''
42
+ opt.separator 'Options:'
43
+ opt.on('--capybara=BACKEND', 'Generate a feature that uses a particular Capybara backend') do |backend|
44
+ options[:capybara] = backend
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,65 @@
1
+ if Rails.version.to_f >= 3.0
2
+ module ActionController #:nodoc:
3
+ module AllowRescueException
4
+ extend ActiveSupport::Concern
5
+ include ActiveSupport::Rescuable
6
+
7
+ private
8
+ def process_action(*args)
9
+ if ActionController::Base.allow_rescue
10
+ super
11
+ else
12
+ begin
13
+ super
14
+ rescue Exception => exception
15
+ raise(exception)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ ActionController::Base.class_eval do
23
+ cattr_accessor :allow_rescue
24
+ include ActionController::AllowRescueException
25
+ end
26
+ else
27
+ ActionController::Base.class_eval do
28
+ cattr_accessor :allow_rescue
29
+
30
+ alias_method :rescue_action_without_bypass, :rescue_action
31
+
32
+ def rescue_action(exception)
33
+ if ActionController::Base.allow_rescue
34
+ rescue_action_without_bypass(exception)
35
+ else
36
+ raise exception
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ begin
43
+ ActionController::Failsafe.class_eval do
44
+ alias_method :failsafe_response_without_bypass, :failsafe_response
45
+
46
+ def failsafe_response(exception)
47
+ raise exception
48
+ end
49
+ end
50
+ rescue NameError # Failsafe was introduced in Rails 2.3.2
51
+ ActionController::Dispatcher.class_eval do
52
+ def self.failsafe_response(output, status, exception = nil)
53
+ raise exception
54
+ end
55
+ end
56
+ end
57
+
58
+ Before('@allow-rescue') do
59
+ @__orig_allow_rescue = ActionController::Base.allow_rescue
60
+ ActionController::Base.allow_rescue = true
61
+ end
62
+
63
+ After('@allow-rescue') do
64
+ ActionController::Base.allow_rescue = @__orig_allow_rescue
65
+ end
@@ -0,0 +1,34 @@
1
+ if defined?(ActiveRecord::Base)
2
+ Before do
3
+ $__cucumber_global_use_txn = !!Cucumber::Rails::World.use_transactional_fixtures if $__cucumber_global_use_txn.nil?
4
+ end
5
+
6
+ Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do
7
+ Cucumber::Rails::World.use_transactional_fixtures = $__cucumber_global_use_txn
8
+ end
9
+
10
+ Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do
11
+ Cucumber::Rails::World.use_transactional_fixtures = false
12
+ end
13
+
14
+ Before do
15
+ if Cucumber::Rails::World.use_transactional_fixtures
16
+ run_callbacks :setup if respond_to?(:run_callbacks)
17
+ else
18
+ DatabaseCleaner.start
19
+ end
20
+ ActionMailer::Base.deliveries = [] if defined?(ActionMailer::Base)
21
+ end
22
+
23
+ After do
24
+ if Cucumber::Rails::World.use_transactional_fixtures
25
+ run_callbacks :teardown if respond_to?(:run_callbacks)
26
+ else
27
+ DatabaseCleaner.clean
28
+ end
29
+ end
30
+ else
31
+ module Cucumber::Rails
32
+ def World.fixture_table_names; []; end # Workaround for projects that don't use ActiveRecord
33
+ end
34
+ end