cucumber-rails 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ Manifest
2
+ pkg
3
+ doc
@@ -0,0 +1,33 @@
1
+ = cucumber-rails
2
+
3
+ Extracted the Rails generators from the Cucumber gem, inspired by
4
+ {this posting}[http://groups.google.com/group/cukes/browse_thread/thread/b9b8ff6301393c19"]
5
+ on the Cukes Mailing List.
6
+
7
+ The goal is to provide i18n of the webrat_steps.rb plus some other useful
8
+ enhancements.
9
+
10
+ == Install
11
+
12
+ gem install cucumber-rails
13
+
14
+ == Usage
15
+
16
+ Once you install the gem, the generators will be available to all Rails
17
+ applications on your system. If you run script/generate without any
18
+ additional arguments you should see the available generators listed.
19
+
20
+ To run the generator, go to your rails project directory and call it
21
+ using the script/generate or script/destroy command.
22
+
23
+ script/generate cucumber
24
+
25
+
26
+ == Included Generators
27
+
28
+ * cucumber: Sets up Cucumber in your Rails project
29
+ * feature: Generates a skeleton for a new feature
30
+
31
+ To view the README for each generator, run it with the --help option.
32
+
33
+ script/generate cucumber --help
@@ -0,0 +1,16 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gemspec|
4
+ gemspec.name = "cucumber-rails"
5
+ gemspec.summary = "Rails Generators for Cucumber"
6
+ gemspec.description = "Rails Generators for Cucumber"
7
+ gemspec.email = "mail@dennisbloete.de"
8
+ gemspec.homepage = "http://github.com/dbloete/cucumber-rails"
9
+ gemspec.authors = ["Dennis Blöte"]
10
+ end
11
+ Jeweler::GemcutterTasks.new
12
+ rescue LoadError
13
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
14
+ end
15
+
16
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{cucumber-rails}
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Dennis Bl\303\266te"]
12
+ s.date = %q{2009-11-07}
13
+ s.description = %q{Rails Generators for Cucumber}
14
+ s.email = %q{mail@dennisbloete.de}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "cucumber-rails.gemspec",
24
+ "lib/cucumber-rails.rb",
25
+ "rails_generators/cucumber/USAGE",
26
+ "rails_generators/cucumber/cucumber_generator.rb",
27
+ "rails_generators/cucumber/templates/cucumber",
28
+ "rails_generators/cucumber/templates/cucumber.rake",
29
+ "rails_generators/cucumber/templates/cucumber_environment.rb",
30
+ "rails_generators/cucumber/templates/env.rb",
31
+ "rails_generators/cucumber/templates/paths.rb",
32
+ "rails_generators/cucumber/templates/spork_env.rb",
33
+ "rails_generators/cucumber/templates/version_check.rb",
34
+ "rails_generators/cucumber/templates/webrat_steps.rb",
35
+ "rails_generators/feature/USAGE",
36
+ "rails_generators/feature/feature_generator.rb",
37
+ "rails_generators/feature/templates/feature.erb",
38
+ "rails_generators/feature/templates/steps.erb"
39
+ ]
40
+ s.homepage = %q{http://github.com/dbloete/cucumber-rails}
41
+ s.rdoc_options = ["--charset=UTF-8"]
42
+ s.require_paths = ["lib"]
43
+ s.rubygems_version = %q{1.3.5}
44
+ s.summary = %q{Rails Generators for Cucumber}
45
+
46
+ if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
51
+ else
52
+ end
53
+ else
54
+ end
55
+ end
56
+
@@ -0,0 +1,3 @@
1
+ module CucumberRails
2
+ # nothing to see here, the real action is under rails_generators
3
+ end
@@ -0,0 +1,11 @@
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, which you can use to generate skeletons
8
+ for new features.
9
+
10
+ Examples:
11
+ `./script/generate cucumber`
@@ -0,0 +1,117 @@
1
+ require 'rbconfig'
2
+ require 'cucumber/platform'
3
+
4
+ # This generator bootstraps a Rails project for use with Cucumber
5
+ class CucumberGenerator < Rails::Generator::Base
6
+ DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
7
+ Config::CONFIG['ruby_install_name'])
8
+
9
+ attr_accessor :framework
10
+
11
+ def manifest
12
+ record do |m|
13
+ m.directory 'features/step_definitions'
14
+ m.template 'webrat_steps.rb', 'features/step_definitions/webrat_steps.rb'
15
+ m.template'cucumber_environment.rb', 'config/environments/cucumber.rb',
16
+ :assigns => { :cucumber_version => ::Cucumber::VERSION }
17
+
18
+ m.gsub_file 'config/database.yml', /test:.*\n/, "test: &TEST\n"
19
+ unless File.read('config/database.yml').include? 'cucumber:'
20
+ m.gsub_file 'config/database.yml', /\z/, "\ncucumber:\n <<: *TEST"
21
+ end
22
+
23
+ m.directory 'features/support'
24
+ if spork?
25
+ m.template'spork_env.rb', 'features/support/env.rb'
26
+ else
27
+ m.template 'env.rb', 'features/support/env.rb'
28
+ end
29
+ m.template 'paths.rb', 'features/support/paths.rb'
30
+ m.template 'version_check.rb', 'features/support/version_check.rb'
31
+
32
+ m.directory 'lib/tasks'
33
+ m.template'cucumber.rake', 'lib/tasks/cucumber.rake'
34
+
35
+ m.file 'cucumber', 'script/cucumber', {
36
+ :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang]
37
+ }
38
+ end
39
+ end
40
+
41
+ def framework
42
+ options[:framework] ||= detect_default_framework!
43
+ end
44
+
45
+ def spork?
46
+ options[:spork]
47
+ end
48
+
49
+ protected
50
+
51
+ def detect_default_framework!
52
+ require 'rubygems'
53
+ rspec! || testunit!
54
+ raise "I don't know what test framework you want. Use --rspec or --testunit, or gem install rspec or test-unit." unless @default_framework
55
+ @default_framework
56
+ end
57
+
58
+ def rspec!
59
+ begin
60
+ require 'spec'
61
+ @default_framework = :rspec
62
+ rescue LoadError
63
+ false
64
+ end
65
+ end
66
+
67
+ def testunit!
68
+ begin
69
+ require 'test/unit'
70
+ @default_framework = :testunit
71
+ rescue LoadError
72
+ false
73
+ end
74
+ end
75
+
76
+ def banner
77
+ "Usage: #{$0} cucumber"
78
+ end
79
+
80
+ def after_generate
81
+ require 'cucumber/formatter/ansicolor'
82
+ extend Cucumber::Formatter::ANSIColor
83
+
84
+ if @default_framework
85
+ puts <<-WARNING
86
+
87
+ #{yellow_cukes(15)}
88
+
89
+ #{yellow_cukes(1)} T E S T F R A M E W O R K A L E R T #{yellow_cukes(1)}
90
+
91
+ You didn't explicitly generate with --rspec or --testunit, so I looked at
92
+ your gems and saw that you had #{green(@default_framework.to_s)} installed, so I went with that.
93
+ If you want something else, be specific about it. Otherwise, relax.
94
+
95
+ #{yellow_cukes(15)}
96
+
97
+ WARNING
98
+ end
99
+ end
100
+
101
+ def add_options!(opt)
102
+ opt.separator ''
103
+ opt.separator 'Options:'
104
+ opt.on('--rspec', "Setup cucumber for use with RSpec") do |value|
105
+ options[:framework] = :rspec
106
+ end
107
+
108
+ opt.on('--testunit', "Setup cucumber for use with test/unit") do |value|
109
+ options[:framework] = :testunit
110
+ end
111
+
112
+ opt.on('--spork', 'Setup cucumber for use with Spork') do |value|
113
+ options[:spork] = true
114
+ end
115
+ end
116
+
117
+ end
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ vendored_cucumber_binary = Dir[File.join(File.dirname(__FILE__),
4
+ '..',
5
+ 'vendor',
6
+ '{gems,plugins}',
7
+ 'cucumber*',
8
+ 'bin',
9
+ 'cucumber')].first
10
+
11
+ if vendored_cucumber_binary
12
+ load File.expand_path(vendored_cucumber_binary)
13
+ else
14
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
15
+ require 'cucumber'
16
+ load Cucumber::BINARY
17
+ end
@@ -0,0 +1,46 @@
1
+ # This file was generated by
2
+ # Find vendored gem or plugin of cucumber
3
+ vendored_cucumber_dir = Dir["#{RAILS_ROOT}/vendor/{gems,plugins}/cucumber*"].first
4
+ $LOAD_PATH.unshift("#{vendored_cucumber_dir}/lib") unless vendored_cucumber_dir.nil?
5
+
6
+ unless ARGV.any? {|a| a =~ /^gems/}
7
+
8
+ begin
9
+ require 'cucumber/rake/task'
10
+
11
+ # Use vendored cucumber binary if possible. If it's not vendored,
12
+ # Cucumber::Rake::Task will automatically use installed gem's cucumber binary
13
+ vendored_cucumber_binary = "#{vendored_cucumber_dir}/bin/cucumber" unless vendored_cucumber_dir.nil?
14
+
15
+ namespace :cucumber do
16
+ Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
17
+ t.binary = vendored_cucumber_binary
18
+ t.fork = true # You may get faster startup if you set this to false
19
+ t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}<%= spork? ? ' --drb' : '' %>"
20
+ end
21
+
22
+ Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
23
+ t.binary = vendored_cucumber_binary
24
+ t.fork = true # You may get faster startup if you set this to false
25
+ t.cucumber_opts = "--color --tags @wip:2 --wip --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}<%= spork? ? ' --drb' : '' %>"
26
+ end
27
+
28
+ desc 'Run all features'
29
+ task :all => [:ok, :wip]
30
+ end
31
+ desc 'Alias for cucumber:ok'
32
+ task :cucumber => 'cucumber:ok'
33
+
34
+ task :default => :cucumber
35
+
36
+ task :features => :cucumber do
37
+ STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
38
+ end
39
+ rescue LoadError
40
+ desc 'cucumber rake task not available (cucumber not installed)'
41
+ task :cucumber do
42
+ abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,30 @@
1
+ # IMPORTANT: This file was generated by Cucumber <%= Cucumber::VERSION %>
2
+ # Edit at your own peril - it's recommended to regenerate this file
3
+ # in the future when you upgrade to a newer version of Cucumber.
4
+
5
+ config.cache_classes = true # This must be true for Cucumber to operate correctly!
6
+
7
+ # Log error messages when you accidentally call methods on nil.
8
+ config.whiny_nils = true
9
+
10
+ # Show full error reports and disable caching
11
+ config.action_controller.consider_all_requests_local = true
12
+ config.action_controller.perform_caching = false
13
+
14
+ # Disable request forgery protection in test environment
15
+ config.action_controller.allow_forgery_protection = false
16
+
17
+ # Tell Action Mailer not to deliver emails to the real world.
18
+ # The :test delivery method accumulates sent emails in the
19
+ # ActionMailer::Base.deliveries array.
20
+ config.action_mailer.delivery_method = :test
21
+
22
+ config.gem 'cucumber', :lib => false, :version => '>=<%= cucumber_version %>' unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber'))
23
+ config.gem 'webrat', :lib => false, :version => '>=0.5.3' unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat'))
24
+ <% if framework == :rspec -%>
25
+ config.gem 'rspec', :lib => false, :version => '>=1.2.9' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec'))
26
+ config.gem 'rspec-rails', :lib => false, :version => '>=1.2.9' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails'))
27
+ <% end %>
28
+ <% if spork? -%>
29
+ config.gem 'spork', :lib => false, :version => '>=0.7.3' unless File.directory?(File.join(Rails.root, 'vendor/plugins/spork'))
30
+ <% end %>
@@ -0,0 +1,49 @@
1
+ # IMPORTANT: This file was generated by Cucumber <%= Cucumber::VERSION %>
2
+ # Edit at your own peril - it's recommended to regenerate this file
3
+ # in the future when you upgrade to a newer version of Cucumber.
4
+ # Consider adding your own code to a new file instead of editing this one.
5
+
6
+ # Sets up the Rails environment for Cucumber
7
+ ENV["RAILS_ENV"] ||= "cucumber"
8
+ require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
9
+ require 'cucumber/rails/world'
10
+
11
+ # If you set this to true, each scenario will run in a database transaction.
12
+ # You can still turn off transactions on a per-scenario basis, simply tagging
13
+ # a feature or scenario with the @no-txn tag.
14
+ #
15
+ # If you set this to false, transactions will be off for all scenarios,
16
+ # regardless of whether you use @no-txn or not.
17
+ #
18
+ # Beware that turning transactions off will leave data in your database
19
+ # after each scenario, which can lead to hard-to-debug failures in
20
+ # subsequent scenarios. If you do this, we recommend you create a Before
21
+ # block that will explicitly put your database in a known state.
22
+ Cucumber::Rails::World.use_transactional_fixtures = true
23
+
24
+ # If you set this to false, any error raised from within your app will bubble
25
+ # up to your step definition and out to cucumber unless you catch it somewhere
26
+ # on the way. You can make Rails rescue errors and render error pages on a
27
+ # per-scenario basis by tagging a scenario or feature with the @allow-rescue tag.
28
+ #
29
+ # If you set this to true, Rails will rescue all errors and render error
30
+ # pages, more or less in the same way your application would behave in the
31
+ # default production environment. It's not recommended to do this for all
32
+ # of your scenarios, as this makes it hard to discover errors in your application.
33
+ ActionController::Base.allow_rescue = false
34
+
35
+ require 'cucumber'
36
+ # Comment out the next line if you don't want Cucumber Unicode support
37
+ require 'cucumber/formatter/unicode'
38
+ require 'cucumber/webrat/element_locator' # Lets you do table.diff!(element_at('#my_table_or_dl_or_ul_or_ol').to_table)
39
+ <% if framework == :rspec -%>
40
+ require 'cucumber/rails/rspec'
41
+ <% end -%>
42
+
43
+ require 'webrat'
44
+ require 'webrat/core/matchers'
45
+ Webrat.configure do |config|
46
+ config.mode = :rails
47
+ config.open_error_files = false # Set to true if you want error pages to pop up in the browser
48
+ end
49
+
@@ -0,0 +1,27 @@
1
+ module NavigationHelpers
2
+ # Maps a name to a path. Used by the
3
+ #
4
+ # When /^I go to (.+)$/ do |page_name|
5
+ #
6
+ # step definition in webrat_steps.rb
7
+ #
8
+ def path_to(page_name)
9
+ case page_name
10
+
11
+ when /the home\s?page/
12
+ '/'
13
+
14
+ # Add more mappings here.
15
+ # Here is a more fancy example:
16
+ #
17
+ # when /^(.*)'s profile page$/i
18
+ # user_profile_path(User.find_by_login($1))
19
+
20
+ else
21
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
22
+ "Now, go and add a mapping in #{__FILE__}"
23
+ end
24
+ end
25
+ end
26
+
27
+ World(NavigationHelpers)
@@ -0,0 +1,57 @@
1
+ # IMPORTANT: This file was generated by Cucumber <%= Cucumber::VERSION %>
2
+ # Edit at your own peril - it's recommended to regenerate this file
3
+ # in the future when you upgrade to a newer version of Cucumber.
4
+ # Consider adding your own code to a new file instead of editing this one.
5
+
6
+ require 'rubygems'
7
+ require 'spork'
8
+
9
+ Spork.prefork do
10
+ # Sets up the Rails environment for Cucumber
11
+ ENV["RAILS_ENV"] = "cucumber"
12
+ require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
13
+ require 'cucumber/rails/world'
14
+
15
+ require 'cucumber'
16
+ # Comment out the next line if you don't want Cucumber Unicode support
17
+ require 'cucumber/formatter/unicode'
18
+ require 'cucumber/webrat/element_locator' # Lets you do table.diff!(element_at('#my_table_or_dl_or_ul_or_ol').to_table)
19
+ <% if framework == :rspec -%>
20
+ require 'cucumber/rails/rspec'
21
+ <% end -%>
22
+
23
+ require 'webrat'
24
+ require 'webrat/core/matchers'
25
+ Webrat.configure do |config|
26
+ config.mode = :rails
27
+ config.open_error_files = false # Set to true if you want error pages to pop up in the browser
28
+ end
29
+ end
30
+
31
+ Spork.each_run do
32
+ # This code will be run each time you start cucumber.
33
+
34
+ # If you set this to true, each scenario will run in a database transaction.
35
+ # You can still turn off transactions on a per-scenario basis, simply tagging
36
+ # a feature or scenario with the @no-txn tag.
37
+ #
38
+ # If you set this to false, transactions will be off for all scenarios,
39
+ # regardless of whether you use @no-txn or not.
40
+ #
41
+ # Beware that turning transactions off will leave data in your database
42
+ # after each scenario, which can lead to hard-to-debug failures in
43
+ # subsequent scenarios. If you do this, we recommend you create a Before
44
+ # block that will explicitly put your database in a known state.
45
+ Cucumber::Rails::World.use_transactional_fixtures = true
46
+
47
+ # If you set this to false, any error raised from within your app will bubble
48
+ # up to your step definition and out to cucumber unless you catch it somewhere
49
+ # on the way. You can make Rails rescue errors and render error pages on a
50
+ # per-scenario basis by tagging a scenario or feature with the @allow-rescue tag.
51
+ #
52
+ # If you set this to true, Rails will rescue all errors and render error
53
+ # pages, more or less in the same way your application would behave in the
54
+ # default production environment. It's not recommended to do this for all
55
+ # of your scenarions, as this makes it hard to discover errors in your application.
56
+ ActionController::Base.allow_rescue = false
57
+ end
@@ -0,0 +1,31 @@
1
+ require 'cucumber/formatter/ansicolor'
2
+ extend Cucumber::Formatter::ANSIColor
3
+ if Cucumber::VERSION != '<%= Cucumber::VERSION %>'
4
+ warning = <<-WARNING
5
+ #{red_cukes(15)}
6
+
7
+ #{red_cukes(1)} R O T T E N C U C U M B E R A L E R T #{red_cukes(1)}
8
+
9
+ Your #{__FILE__.gsub(/version_check.rb$/, 'env.rb')} file was generated with Cucumber <%= Cucumber::VERSION %>,
10
+ but you seem to be running Cucumber #{Cucumber::VERSION}. If you're running an older
11
+ version than #{Cucumber::VERSION}, just upgrade your gem. If you're running a newer
12
+ version than #{Cucumber::VERSION} you should:
13
+
14
+ 1) Read http://wiki.github.com/aslakhellesoy/cucumber/upgrading
15
+
16
+ 2) Regenerate your cucumber environment with the following command:
17
+
18
+ ruby script/generate cucumber
19
+
20
+ If you get prompted to replace a file, hit 'd' to see the difference.
21
+ When you're sure you have captured any personal edits, confirm that you
22
+ want to overwrite #{__FILE__.gsub(/version_check.rb$/, 'env.rb')} by pressing 'y'. Then reapply any
23
+ personal changes that may have been overwritten, preferably in separate files.
24
+
25
+ This message will then self destruct.
26
+
27
+ #{red_cukes(15)}
28
+ WARNING
29
+ warn(warning)
30
+ at_exit {warn(warning)}
31
+ end
@@ -0,0 +1,241 @@
1
+ # IMPORTANT: This file was generated by Cucumber <%= Cucumber::VERSION %>
2
+ # Edit at your own peril - it's recommended to regenerate this file
3
+ # in the future when you upgrade to a newer version of Cucumber.
4
+ # Consider adding your own code to a new file instead of editing this one.
5
+
6
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
7
+
8
+ # Commonly used webrat steps
9
+ # http://github.com/brynary/webrat
10
+
11
+ Given /^(?:|I )am on (.+)$/ do |page_name|
12
+ visit path_to(page_name)
13
+ end
14
+
15
+ When /^(?:|I )go to (.+)$/ do |page_name|
16
+ visit path_to(page_name)
17
+ end
18
+
19
+ When /^(?:|I )press "([^\"]*)"$/ do |button|
20
+ click_button(button)
21
+ end
22
+
23
+ When /^(?:|I )follow "([^\"]*)"$/ do |link|
24
+ click_link(link)
25
+ end
26
+
27
+ When /^(?:|I )follow "([^\"]*)" within "([^\"]*)"$/ do |link, parent|
28
+ click_link_within(parent, link)
29
+ end
30
+
31
+ When /^(?:|I )fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
32
+ fill_in(field, :with => value)
33
+ end
34
+
35
+ When /^(?:|I )fill in "([^\"]*)" for "([^\"]*)"$/ do |value, field|
36
+ fill_in(field, :with => value)
37
+ end
38
+
39
+ # Use this to fill in an entire form with data from a table. Example:
40
+ #
41
+ # When I fill in the following:
42
+ # | Account Number | 5002 |
43
+ # | Expiry date | 2009-11-01 |
44
+ # | Note | Nice guy |
45
+ # | Wants Email? | |
46
+ #
47
+ # TODO: Add support for checkbox, select og option
48
+ # based on naming conventions.
49
+ #
50
+ When /^(?:|I )fill in the following:$/ do |fields|
51
+ fields.rows_hash.each do |name, value|
52
+ When %{I fill in "#{name}" with "#{value}"}
53
+ end
54
+ end
55
+
56
+ When /^(?:|I )select "([^\"]*)" from "([^\"]*)"$/ do |value, field|
57
+ select(value, :from => field)
58
+ end
59
+
60
+ # Use this step in conjunction with Rail's datetime_select helper. For example:
61
+ # When I select "December 25, 2008 10:00" as the date and time
62
+ When /^(?:|I )select "([^\"]*)" as the date and time$/ do |time|
63
+ select_datetime(time)
64
+ end
65
+
66
+ # Use this step when using multiple datetime_select helpers on a page or
67
+ # you want to specify which datetime to select. Given the following view:
68
+ # <%%= f.label :preferred %><br />
69
+ # <%%= f.datetime_select :preferred %>
70
+ # <%%= f.label :alternative %><br />
71
+ # <%%= f.datetime_select :alternative %>
72
+ # The following steps would fill out the form:
73
+ # When I select "November 23, 2004 11:20" as the "Preferred" date and time
74
+ # And I select "November 25, 2004 10:30" as the "Alternative" date and time
75
+ When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" date and time$/ do |datetime, datetime_label|
76
+ select_datetime(datetime, :from => datetime_label)
77
+ end
78
+
79
+ # Use this step in conjunction with Rail's time_select helper. For example:
80
+ # When I select "2:20PM" as the time
81
+ # Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
82
+ # will convert the 2:20PM to 14:20 and then select it.
83
+ When /^(?:|I )select "([^\"]*)" as the time$/ do |time|
84
+ select_time(time)
85
+ end
86
+
87
+ # Use this step when using multiple time_select helpers on a page or you want to
88
+ # specify the name of the time on the form. For example:
89
+ # When I select "7:30AM" as the "Gym" time
90
+ When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" time$/ do |time, time_label|
91
+ select_time(time, :from => time_label)
92
+ end
93
+
94
+ # Use this step in conjunction with Rail's date_select helper. For example:
95
+ # When I select "February 20, 1981" as the date
96
+ When /^(?:|I )select "([^\"]*)" as the date$/ do |date|
97
+ select_date(date)
98
+ end
99
+
100
+ # Use this step when using multiple date_select helpers on one page or
101
+ # you want to specify the name of the date on the form. For example:
102
+ # When I select "April 26, 1982" as the "Date of Birth" date
103
+ When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label|
104
+ select_date(date, :from => date_label)
105
+ end
106
+
107
+ When /^(?:|I )check "([^\"]*)"$/ do |field|
108
+ check(field)
109
+ end
110
+
111
+ When /^(?:|I )uncheck "([^\"]*)"$/ do |field|
112
+ uncheck(field)
113
+ end
114
+
115
+ When /^(?:|I )choose "([^\"]*)"$/ do |field|
116
+ choose(field)
117
+ end
118
+
119
+ When /^(?:|I )attach the file at "([^\"]*)" to "([^\"]*)"$/ do |path, field|
120
+ attach_file(field, path)
121
+ end
122
+
123
+ Then /^(?:|I )should see "([^\"]*)"$/ do |text|
124
+ <% if framework == :rspec -%>
125
+ response.should contain(text)
126
+ <% else -%>
127
+ assert_contain text
128
+ <% end -%>
129
+ end
130
+
131
+ Then /^(?:|I )should see "([^\"]*)" within "([^\"]*)"$/ do |text, selector|
132
+ within(selector) do |content|
133
+ <% if framework == :rspec -%>
134
+ content.should contain(text)
135
+ <% else -%>
136
+ assert content.include?(text)
137
+ <% end -%>
138
+ end
139
+ end
140
+
141
+ Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
142
+ regexp = Regexp.new(regexp)
143
+ <% if framework == :rspec -%>
144
+ response.should contain(regexp)
145
+ <% else -%>
146
+ assert_contain regexp
147
+ <% end -%>
148
+ end
149
+
150
+ Then /^(?:|I )should see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector|
151
+ within(selector) do |content|
152
+ regexp = Regexp.new(regexp)
153
+ <% if framework == :rspec -%>
154
+ content.should contain(regexp)
155
+ <% else -%>
156
+ assert content =~ regexp
157
+ <% end -%>
158
+ end
159
+ end
160
+
161
+ Then /^(?:|I )should not see "([^\"]*)"$/ do |text|
162
+ <% if framework == :rspec -%>
163
+ response.should_not contain(text)
164
+ <% else -%>
165
+ assert_not_contain text
166
+ <% end -%>
167
+ end
168
+
169
+ Then /^(?:|I )should not see "([^\"]*)" within "([^\"]*)"$/ do |text, selector|
170
+ within(selector) do |content|
171
+ <% if framework == :rspec -%>
172
+ content.should_not contain(text)
173
+ <% else -%>
174
+ assert !content.include?(text)
175
+ <% end -%>
176
+ end
177
+ end
178
+
179
+ Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
180
+ regexp = Regexp.new(regexp)
181
+ <% if framework == :rspec -%>
182
+ response.should_not contain(regexp)
183
+ <% else -%>
184
+ assert_not_contain regexp
185
+ <% end -%>
186
+ end
187
+
188
+ Then /^(?:|I )should not see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector|
189
+ within(selector) do |content|
190
+ regexp = Regexp.new(regexp)
191
+ <% if framework == :rspec -%>
192
+ content.should_not contain(regexp)
193
+ <% else -%>
194
+ assert content !~ regexp
195
+ <% end -%>
196
+ end
197
+ end
198
+
199
+ Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value|
200
+ <% if framework == :rspec -%>
201
+ field_labeled(field).value.should =~ /#{value}/
202
+ <% else -%>
203
+ assert_match(/#{value}/, field_labeled(field).value)
204
+ <% end -%>
205
+ end
206
+
207
+ Then /^the "([^\"]*)" field should not contain "([^\"]*)"$/ do |field, value|
208
+ <% if framework == :rspec -%>
209
+ field_labeled(field).value.should_not =~ /#{value}/
210
+ <% else -%>
211
+ assert_no_match(/#{value}/, field_labeled(field).value)
212
+ <% end -%>
213
+ end
214
+
215
+ Then /^the "([^\"]*)" checkbox should be checked$/ do |label|
216
+ <% if framework == :rspec -%>
217
+ field_labeled(label).should be_checked
218
+ <% else -%>
219
+ assert field_labeled(label).checked?
220
+ <% end -%>
221
+ end
222
+
223
+ Then /^the "([^\"]*)" checkbox should not be checked$/ do |label|
224
+ <% if framework == :rspec -%>
225
+ field_labeled(label).should_not be_checked
226
+ <% else -%>
227
+ assert !field_labeled(label).checked?
228
+ <% end -%>
229
+ end
230
+
231
+ Then /^(?:|I )should be on (.+)$/ do |page_name|
232
+ <% if framework == :rspec -%>
233
+ URI.parse(current_url).path.should == path_to(page_name)
234
+ <% else -%>
235
+ assert_equal path_to(page_name), URI.parse(current_url).path
236
+ <% end -%>
237
+ end
238
+
239
+ Then /^show me the page$/ do
240
+ save_and_open_page
241
+ 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,40 @@
1
+ # This generator generates a baic feature.
2
+ class FeatureGenerator < Rails::Generator::NamedBase
3
+ def manifest
4
+ record do |m|
5
+ m.directory 'features/step_definitions'
6
+ m.template 'feature.erb', "features/manage_#{plural_name}.feature"
7
+ m.template 'steps.erb', "features/step_definitions/#{singular_name}_steps.rb"
8
+
9
+ m.gsub_file 'features/support/paths.rb', /'\/'/mi do |match|
10
+ "#{match}\n when /the new #{singular_name} page/\n new_#{singular_name}_path\n"
11
+ end
12
+ end
13
+ end
14
+
15
+ class NamedArg
16
+ attr_reader :name
17
+
18
+ def initialize(s)
19
+ @name, @type = *s.split(':')
20
+ end
21
+
22
+ def value(n)
23
+ if @type == 'boolean'
24
+ (n % 2) == 0
25
+ else
26
+ "#{@name} #{n}"
27
+ end
28
+ end
29
+ end
30
+
31
+ def named_args
32
+ args.map{|arg| NamedArg.new(arg)}
33
+ end
34
+
35
+ protected
36
+
37
+ def banner
38
+ "Usage: #{$0} feature ModelName [field:type, field:type]"
39
+ end
40
+ end
@@ -0,0 +1,31 @@
1
+ Feature: Manage <%= plural_name %>
2
+ In order to [goal]
3
+ [stakeholder]
4
+ wants [behaviour]
5
+
6
+ Scenario: Register new <%= singular_name %>
7
+ Given I am on the new <%= singular_name %> page
8
+ <% keyword = 'When' -%>
9
+ <% named_args.each do |arg| -%>
10
+ <%= keyword %> I fill in "<%= arg.name.humanize %>" with "<%= arg.value(1) %>"
11
+ <% keyword = 'And' -%>
12
+ <% end -%>
13
+ And I press "Create"
14
+ <% keyword = 'Then' -%>
15
+ <% named_args.each do |arg| -%>
16
+ <%= keyword %> I should see "<%= arg.value(1) %>"
17
+ <% keyword = 'And' -%>
18
+ <% end -%>
19
+
20
+ Scenario: Delete <%= singular_name %>
21
+ Given the following <%= plural_name %>:
22
+ |<%= named_args.map(&:name).join('|') %>|
23
+ <% (1..4).each do |n| -%>
24
+ |<%= named_args.map{|arg| arg.value(n)}.join('|') %>|
25
+ <% end -%>
26
+ When I delete the 3rd <%= singular_name %>
27
+ Then I should see the following <%= plural_name %>:
28
+ |<%= named_args.map{|arg| arg.name.humanize}.join('|') %>|
29
+ <% [1,2,4].each do |n| -%>
30
+ |<%= named_args.map{|arg| arg.value(n)}.join('|') %>|
31
+ <% end -%>
@@ -0,0 +1,14 @@
1
+ Given /^the following <%= plural_name %>:$/ do |<%= plural_name %>|
2
+ <%= class_name %>.create!(<%= plural_name %>.hashes)
3
+ end
4
+
5
+ When /^I delete the (\d+)(?:st|nd|rd|th) <%= singular_name %>$/ do |pos|
6
+ visit <%= plural_name %>_url
7
+ within("table > tr:nth-child(#{pos.to_i+1})") do
8
+ click_link "Destroy"
9
+ end
10
+ end
11
+
12
+ Then /^I should see the following <%= plural_name %>:$/ do |expected_<%= plural_name %>_table|
13
+ expected_<%= plural_name %>_table.diff!(table_at('table').to_a)
14
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cucumber-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - "Dennis Bl\xC3\xB6te"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-07 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Rails Generators for Cucumber
17
+ email: mail@dennisbloete.de
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ files:
25
+ - .gitignore
26
+ - README.rdoc
27
+ - Rakefile
28
+ - VERSION
29
+ - cucumber-rails.gemspec
30
+ - lib/cucumber-rails.rb
31
+ - rails_generators/cucumber/USAGE
32
+ - rails_generators/cucumber/cucumber_generator.rb
33
+ - rails_generators/cucumber/templates/cucumber
34
+ - rails_generators/cucumber/templates/cucumber.rake
35
+ - rails_generators/cucumber/templates/cucumber_environment.rb
36
+ - rails_generators/cucumber/templates/env.rb
37
+ - rails_generators/cucumber/templates/paths.rb
38
+ - rails_generators/cucumber/templates/spork_env.rb
39
+ - rails_generators/cucumber/templates/version_check.rb
40
+ - rails_generators/cucumber/templates/webrat_steps.rb
41
+ - rails_generators/feature/USAGE
42
+ - rails_generators/feature/feature_generator.rb
43
+ - rails_generators/feature/templates/feature.erb
44
+ - rails_generators/feature/templates/steps.erb
45
+ has_rdoc: true
46
+ homepage: http://github.com/dbloete/cucumber-rails
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options:
51
+ - --charset=UTF-8
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.3.5
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Rails Generators for Cucumber
73
+ test_files: []
74
+