Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dbloete committed Nov 7, 2009
0 parents commit 1a1c42c
Show file tree
Hide file tree
Showing 20 changed files with 788 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest
pkg
doc
8 changes: 8 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
h1. cucumber-rails

Extracted the Rails generators from the Cucumber gem, inspired by this
posting on the Cukes Mailing List:
http://groups.google.com/group/cukes/browse_thread/thread/b9b8ff6301393c19

The goal is to provide i18n of the webrat_steps.rb plus some other useful
enhancements.
16 changes: 16 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
begin
require 'jeweler'
Jeweler::Tasks.new do |gemspec|
gemspec.name = "cucumber-rails"
gemspec.summary = "Rails Generators for Cucumber"
gemspec.description = "Rails Generators for Cucumber"
gemspec.email = "[email protected]"
gemspec.homepage = "http://github.com/dbloete/cucumber-rails"
gemspec.authors = ["Dennis Blöte"]
end
Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
end

Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.0
34 changes: 34 additions & 0 deletions cucumber-rails.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = %q{cucumber-rails}
s.version = "0.0.0"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Dennis Bl\303\266te"]
s.date = %q{2009-11-07}
s.description = %q{Rails Generators for Cucumber}
s.email = %q{[email protected]}
s.extra_rdoc_files = [
"README.rdoc"
]
s.homepage = %q{http://github.com/dbloete/cucumber-rails}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.5}
s.summary = %q{Rails Generators for Cucumber}

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3

if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
else
end
else
end
end

3 changes: 3 additions & 0 deletions lib/cucumber-rails.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module CucumberRails
# nothing to see here, the real action is under rails_generators
end
11 changes: 11 additions & 0 deletions rails_generators/cucumber/USAGE
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Description:
Sets up Cucumber in your Rails project. After running this generator you will
get a new rake task called features.

This also generates the necessary files in the features directory.

Also see the feature generator, which you can use to generate skeletons
for new features.

Examples:
`./script/generate cucumber`
117 changes: 117 additions & 0 deletions rails_generators/cucumber/cucumber_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
require 'rbconfig'
require 'cucumber/platform'

# This generator bootstraps a Rails project for use with Cucumber
class CucumberGenerator < Rails::Generator::Base
DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
Config::CONFIG['ruby_install_name'])

attr_accessor :framework

def manifest
record do |m|
m.directory 'features/step_definitions'
m.template 'webrat_steps.rb', 'features/step_definitions/webrat_steps.rb'
m.template'cucumber_environment.rb', 'config/environments/cucumber.rb',
:assigns => { :cucumber_version => ::Cucumber::VERSION }

m.gsub_file 'config/database.yml', /test:.*\n/, "test: &TEST\n"
unless File.read('config/database.yml').include? 'cucumber:'
m.gsub_file 'config/database.yml', /\z/, "\ncucumber:\n <<: *TEST"
end

m.directory 'features/support'
if spork?
m.template'spork_env.rb', 'features/support/env.rb'
else
m.template 'env.rb', 'features/support/env.rb'
end
m.template 'paths.rb', 'features/support/paths.rb'
m.template 'version_check.rb', 'features/support/version_check.rb'

m.directory 'lib/tasks'
m.template'cucumber.rake', 'lib/tasks/cucumber.rake'

m.file 'cucumber', 'script/cucumber', {
:chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang]
}
end
end

def framework
options[:framework] ||= detect_default_framework!
end

def spork?
options[:spork]
end

protected

def detect_default_framework!
require 'rubygems'
rspec! || testunit!
raise "I don't know what test framework you want. Use --rspec or --testunit, or gem install rspec or test-unit." unless @default_framework
@default_framework
end

def rspec!
begin
require 'spec'
@default_framework = :rspec
rescue LoadError
false
end
end

def testunit!
begin
require 'test/unit'
@default_framework = :testunit
rescue LoadError
false
end
end

def banner
"Usage: #{$0} cucumber"
end

def after_generate
require 'cucumber/formatter/ansicolor'
extend Cucumber::Formatter::ANSIColor

if @default_framework
puts <<-WARNING
#{yellow_cukes(15)}
#{yellow_cukes(1)} T E S T F R A M E W O R K A L E R T #{yellow_cukes(1)}
You didn't explicitly generate with --rspec or --testunit, so I looked at
your gems and saw that you had #{green(@default_framework.to_s)} installed, so I went with that.
If you want something else, be specific about it. Otherwise, relax.
#{yellow_cukes(15)}
WARNING
end
end

def add_options!(opt)
opt.separator ''
opt.separator 'Options:'
opt.on('--rspec', "Setup cucumber for use with RSpec") do |value|
options[:framework] = :rspec
end

opt.on('--testunit', "Setup cucumber for use with test/unit") do |value|
options[:framework] = :testunit
end

opt.on('--spork', 'Setup cucumber for use with Spork') do |value|
options[:spork] = true
end
end

end
17 changes: 17 additions & 0 deletions rails_generators/cucumber/templates/cucumber
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env ruby

vendored_cucumber_binary = Dir[File.join(File.dirname(__FILE__),
'..',
'vendor',
'{gems,plugins}',
'cucumber*',
'bin',
'cucumber')].first

if vendored_cucumber_binary
load File.expand_path(vendored_cucumber_binary)
else
require 'rubygems' unless ENV['NO_RUBYGEMS']
require 'cucumber'
load Cucumber::BINARY
end
46 changes: 46 additions & 0 deletions rails_generators/cucumber/templates/cucumber.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This file was generated by
# Find vendored gem or plugin of cucumber
vendored_cucumber_dir = Dir["#{RAILS_ROOT}/vendor/{gems,plugins}/cucumber*"].first
$LOAD_PATH.unshift("#{vendored_cucumber_dir}/lib") unless vendored_cucumber_dir.nil?

unless ARGV.any? {|a| a =~ /^gems/}

begin
require 'cucumber/rake/task'

# Use vendored cucumber binary if possible. If it's not vendored,
# Cucumber::Rake::Task will automatically use installed gem's cucumber binary
vendored_cucumber_binary = "#{vendored_cucumber_dir}/bin/cucumber" unless vendored_cucumber_dir.nil?

namespace :cucumber do
Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
t.binary = vendored_cucumber_binary
t.fork = true # You may get faster startup if you set this to false
t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}<%= spork? ? ' --drb' : '' %>"
end

Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
t.binary = vendored_cucumber_binary
t.fork = true # You may get faster startup if you set this to false
t.cucumber_opts = "--color --tags @wip:2 --wip --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}<%= spork? ? ' --drb' : '' %>"
end

desc 'Run all features'
task :all => [:ok, :wip]
end
desc 'Alias for cucumber:ok'
task :cucumber => 'cucumber:ok'

task :default => :cucumber

task :features => :cucumber do
STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
end
rescue LoadError
desc 'cucumber rake task not available (cucumber not installed)'
task :cucumber do
abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
end
end

end
30 changes: 30 additions & 0 deletions rails_generators/cucumber/templates/cucumber_environment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# IMPORTANT: This file was generated by Cucumber <%= Cucumber::VERSION %>
# Edit at your own peril - it's recommended to regenerate this file
# in the future when you upgrade to a newer version of Cucumber.

config.cache_classes = true # This must be true for Cucumber to operate correctly!

# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true

# Show full error reports and disable caching
config.action_controller.consider_all_requests_local = true
config.action_controller.perform_caching = false

# Disable request forgery protection in test environment
config.action_controller.allow_forgery_protection = false

# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test

config.gem 'cucumber', :lib => false, :version => '>=<%= cucumber_version %>' unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber'))
config.gem 'webrat', :lib => false, :version => '>=0.5.3' unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat'))
<% if framework == :rspec -%>
config.gem 'rspec', :lib => false, :version => '>=1.2.9' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec'))
config.gem 'rspec-rails', :lib => false, :version => '>=1.2.9' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails'))
<% end %>
<% if spork? -%>
config.gem 'spork', :lib => false, :version => '>=0.7.3' unless File.directory?(File.join(Rails.root, 'vendor/plugins/spork'))
<% end %>
49 changes: 49 additions & 0 deletions rails_generators/cucumber/templates/env.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# IMPORTANT: This file was generated by Cucumber <%= Cucumber::VERSION %>
# Edit at your own peril - it's recommended to regenerate this file
# in the future when you upgrade to a newer version of Cucumber.
# Consider adding your own code to a new file instead of editing this one.

# Sets up the Rails environment for Cucumber
ENV["RAILS_ENV"] ||= "cucumber"
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
require 'cucumber/rails/world'

# If you set this to true, each scenario will run in a database transaction.
# You can still turn off transactions on a per-scenario basis, simply tagging
# a feature or scenario with the @no-txn tag.
#
# If you set this to false, transactions will be off for all scenarios,
# regardless of whether you use @no-txn or not.
#
# Beware that turning transactions off will leave data in your database
# after each scenario, which can lead to hard-to-debug failures in
# subsequent scenarios. If you do this, we recommend you create a Before
# block that will explicitly put your database in a known state.
Cucumber::Rails::World.use_transactional_fixtures = true

# If you set this to false, any error raised from within your app will bubble
# up to your step definition and out to cucumber unless you catch it somewhere
# on the way. You can make Rails rescue errors and render error pages on a
# per-scenario basis by tagging a scenario or feature with the @allow-rescue tag.
#
# If you set this to true, Rails will rescue all errors and render error
# pages, more or less in the same way your application would behave in the
# default production environment. It's not recommended to do this for all
# of your scenarios, as this makes it hard to discover errors in your application.
ActionController::Base.allow_rescue = false

require 'cucumber'
# Comment out the next line if you don't want Cucumber Unicode support
require 'cucumber/formatter/unicode'
require 'cucumber/webrat/element_locator' # Lets you do table.diff!(element_at('#my_table_or_dl_or_ul_or_ol').to_table)
<% if framework == :rspec -%>
require 'cucumber/rails/rspec'
<% end -%>
require 'webrat'
require 'webrat/core/matchers'
Webrat.configure do |config|
config.mode = :rails
config.open_error_files = false # Set to true if you want error pages to pop up in the browser
end
27 changes: 27 additions & 0 deletions rails_generators/cucumber/templates/paths.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module NavigationHelpers
# Maps a name to a path. Used by the
#
# When /^I go to (.+)$/ do |page_name|
#
# step definition in webrat_steps.rb
#
def path_to(page_name)
case page_name

when /the home\s?page/
'/'

# Add more mappings here.
# Here is a more fancy example:
#
# when /^(.*)'s profile page$/i
# user_profile_path(User.find_by_login($1))

else
raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
"Now, go and add a mapping in #{__FILE__}"
end
end
end

World(NavigationHelpers)
Loading

0 comments on commit 1a1c42c

Please sign in to comment.