Skip to content

Commit

Permalink
W00t w00t. Rails3 is working.
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Feb 26, 2010
1 parent c3f77ec commit 892a3fa
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 81 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Manifest
pkg
doc
tmp
tmp
coverage
74 changes: 35 additions & 39 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -1,64 +1,60 @@
= cucumber-rails
= Cucumber-Rails

Extracted the Rails generators from the Cucumber gem, inspired by
{this posting}[http://groups.google.com/group/cukes/browse_thread/thread/b9b8ff6301393c19]
on the Cukes Mailing List.
Cucumber-Rails brings Cucumber to Rails2 and Rails3. It contains 2 generators - one
for bootstrapping your Rails app for Cucumber, and a second one for generating features.

The goal is to provide i18n of the webrat_steps.rb plus some other useful
enhancements.
Cucumber-Rails also contains Cucumber Step Definitions that wrap Capybara or Webrat,
giving you a head start for writing Cucumber features against your Rails app.

== Install
== Installation

Add it to the Gemfile as follows:
=== Rails 3:

gem "cucumber-rails", :git => "[email protected]:alg/cucumber-rails3.git"
Before you can use the generator, add it to your project's Gemfile as follows:

then:
gem "cucumber-rails"

gem bundle
Or if you prefer the latest and greatest:

... and you are ready to go.
gem "cucumber-rails", :git => "[email protected]:aslakhellesoy/cucumber-rails3.git"

== Usage
Then install the gem by running:

Once you install the gem, the generators will be available to all Rails
applications on your system. If you run `script/rails generate` (or `script/generate` on Rails 2.x)
without any additional arguments you should see the available generators listed.
bundle install

To run the generator, go to your rails project directory and call it.
Finally, bootstrap your Rails app by running:

Rails 3:
ruby script/rails generate cucumber:skeleton

script/rails generate cucumber:skeleton
=== Rails 2.x:

Rails 2.x:

script/generate cucumber
Before you can use the generator, install the gem by running:

gem install cucumber-rails

== Included Generators
Finally, bootstrap your Rails app by running:

Rails 3:

* cucumber:skeleton -- Sets up Cucumber in your Rails project
* cucumber:feature -- Generates a skeleton for a new feature
script/generate cucumber

Rails 2:
== Generating a Cucumber feature

* cucumber -- Sets up Cucumber in your Rails project
* feature -- Generates a skeleton for a new feature
IMPORTANT: Only do this if you are new to Cucumber. We recommend you write your
Cucumber features by hand once you get the hang of it.

To view the README for each generator, run it with the --help option.
=== Rails 3:

script/rails generate cucumber:skeleton --help
script/rails generate cucumber:feature --help
Example:

or for Rails 2.x:
ruby script/rails generate cucumber:feature post title:string body:text published:boolean
ruby script/rails generate scaffold post title:string body:text published:boolean
rake db:migrate
rake cucumber

script/generate cucumber --help
script/generate feature --help
=== Rails 2:

== Tests
Example:

This project has tests, but for practical and historical reasons they live in a different project:
http://github.com/aslakhellesoy/cucumber-rails-test/
ruby script/generate feature post title:string body:text published:boolean
ruby script/generate scaffold post title:string body:text published:boolean
rake db:migrate
rake cucumber
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ begin
gemspec.homepage = "http://github.com/aslakhellesoy/cucumber-rails"

gemspec.add_dependency 'cucumber', '>= 0.6.2'
gemspec.add_development_dependency 'aruba', '>= 0.1.5'
end
Jeweler::GemcutterTasks.new
rescue LoadError
Expand Down
5 changes: 3 additions & 2 deletions features/skeleton_rails3.feature
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ Feature: Rails 3
gem 'capybara', :git => 'git://github.com/aslakhellesoy/capybara.git'
"""
And I run "ruby -S bundle install"
And I run "bundle install"
And I successfully run "rake db:migrate"
And I run "rake cucumber"
Then it should pass with:
"""
3 steps (3 passed)
2 scenarios (2 passed)
11 steps (11 passed)
"""

4 changes: 4 additions & 0 deletions generators/cucumber/cucumber_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def driver
options[:driver] ||= detect_current_driver || detect_default_driver
end

def cucumber_rails_env
'cucumber'
end

def self.gem_root
File.expand_path('../../../', __FILE__)
end
Expand Down
18 changes: 13 additions & 5 deletions lib/cucumber/rails/capybara_javascript_emulation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ def self.included(base)
end

def click_with_rails_javascript_emulation
if link_with_onclick_from_rails?
if link_with_non_get_http_method?
Capybara::Driver::RackTest::Form.new(driver, js_form(self[:href], emulated_method)).submit(self)
else
click_without_rails_javascript_emulation
end
end


private

def js_form(action, emulated_method, method = 'POST')
js_form = node.document.create_element('form')
js_form['action'] = action
Expand All @@ -34,12 +34,20 @@ def js_form(action, emulated_method, method = 'POST')
js_form
end

def link_with_onclick_from_rails?
tag_name == 'a' and node['onclick'] =~ /var f = document\.createElement\('form'\); f\.style\.display = 'none';/
def link_with_non_get_http_method?
if ::Rails.version.to_f >= 3.0
tag_name == 'a' && node['data-method'] && node['data-method'] =~ /(?:delete|put|post)/
else
tag_name == 'a' && node['onclick'] && node['onclick'] =~ /var f = document\.createElement\('form'\); f\.style\.display = 'none';/
end
end

def emulated_method
node['onclick'][/m\.setAttribute\('value', '([^']*)'\)/, 1]
if ::Rails.version.to_f >= 3.0
node['data-method']
else
node['onclick'][/m\.setAttribute\('value', '([^']*)'\)/, 1]
end
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/cucumber/skeleton/skeleton_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ def create_feature_support(m = self, rails2 = false)
m.copy_file 'support/paths.rb', 'features/support/paths.rb'

if spork?
m.template 'support/rails3_spork.rb.erb', 'features/support/env.rb'
m.template 'support/rails_spork.rb.erb', 'features/support/env.rb'
else
m.template 'support/rails3.rb.erb', 'features/support/env.rb'
m.template 'support/rails.rb.erb', 'features/support/env.rb'
end
end
end
Expand Down
6 changes: 5 additions & 1 deletion lib/generators/cucumber/skeleton/skeleton_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ def self.gem_root
def self.source_root
File.join(gem_root, 'templates/skeleton')
end


def cucumber_rails_env
'test'
end

private

def framework_from_options
Expand Down
12 changes: 0 additions & 12 deletions templates/skeleton/support/_rails3_beta.rb.erb

This file was deleted.

2 changes: 1 addition & 1 deletion templates/skeleton/support/_rails_prefork.rb.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ENV["RAILS_ENV"] ||= "cucumber"
ENV["RAILS_ENV"] ||= "<%= cucumber_rails_env %>"
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')

require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
Expand Down
4 changes: 0 additions & 4 deletions templates/skeleton/support/rails3.rb.erb

This file was deleted.

13 changes: 0 additions & 13 deletions templates/skeleton/support/rails3_spork.rb.erb

This file was deleted.

0 comments on commit 892a3fa

Please sign in to comment.