Permalink
Browse files

Cuke using BA within a generated Rails app

Adds rake tasks to generate a configured Rails 2.3 app that can
run cukes smoke testing BasicAssumption in the context of Rails
  • Loading branch information...
mattyoho committed Jun 25, 2010
1 parent 91c8ea7 commit 3d32320d613f65da07ccbd9de6549e82b1a24545
View
@@ -1,4 +1,5 @@
require 'spec/rake/spectask'
+require 'cucumber/rake/task'
task :default => :spec
@@ -8,6 +9,10 @@ Spec::Rake::SpecTask.new do |t|
t.spec_opts = %w(-fs --color)
end
+Cucumber::Rake::Task.new(:cucumber) do |t|
+ t.cucumber_opts = %w{--format progress}
+end
+
desc "Run specs with rcov"
Spec::Rake::SpecTask.new(:spec_with_rcov) do |t|
t.spec_files = FileList['spec/**/*_spec.rb']
@@ -26,10 +31,19 @@ namespace :generate do
system 'rails ./tmp/example_app'
Dir.chdir("./tmp/example_app/") do
system "script/generate cucumber"
+ system 'cp ../../templates/environment.rb ./config/'
+ system 'cp ../../templates/custom_steps.rb ./features/step_definitions/'
end
end
end
end
+
+ desc 'Generate scaffolds, etc'
+ task :custom => ['generate:app'] do
+ Dir.chdir("./tmp/example_app/") do
+ system "rake rails:template LOCATION='../../templates/generate_custom.rb'"
+ end
+ end
end
namespace :clobber do
View
@@ -0,0 +1,3 @@
+default: --require features --format progress --tags ~@wip
+pretty: --require features --format pretty --tags ~@wip
+wip: --require features --tags @wip
@@ -0,0 +1,28 @@
+Feature: Rails controllers can make assumptions
+
+ Scenario: controller invokes assume
+ Given a file named "app/controllers/widgets_controller.rb" with:
+ """
+ class WidgetsController < ApplicationController
+ assume(:widget) { Widget.find(params[:id]) }
+ end
+ """
+ And a file named "app/views/widgets/show.html.erb" with:
+ """
+ <blink><%= widget.name %></blink>
+ """
+ And a file named "features/widget_is_viewed_by_visitor.feature" with:
+ """
+ Feature: Widget is viewed by visitor
+ Scenario: success
+ Given a widget named "foobar"
+ When I view the widget
+ Then I should see "foobar"
+ """
+ When I run "cucumber features/widget_is_viewed_by_visitor.feature"
+ Then I should see:
+ """
+ 1 scenario (1 passed)
+ 3 steps
+ """
+
View
@@ -0,0 +1,25 @@
+require 'aruba'
+
+def aruba_path(file_or_dir)
+ File.expand_path("../../../#{file_or_dir.sub('example_app','aruba')}", __FILE__)
+end
+
+def example_app_path(file_or_dir)
+ File.expand_path("../../../#{file_or_dir}", __FILE__)
+end
+
+def write_symlink(file_or_dir)
+ source = example_app_path(file_or_dir)
+ target = aruba_path(file_or_dir)
+ system "ln -s #{source} #{target}"
+end
+
+Before do
+ steps %Q{
+ Given a directory named "touch"
+ }
+
+ Dir['tmp/example_app/*'].each do |file_or_dir|
+ write_symlink(file_or_dir)
+ end
+end
@@ -0,0 +1,8 @@
+Given /^a widget named (.+)$/ do |widget_name|
+ @widget = Widget.create!(:name => widget_name)
+end
+
+When /^I view the widget$/ do
+ visit widget_path(@widget)
+end
+
View
@@ -0,0 +1,42 @@
+# Be sure to restart your server when you modify this file
+
+# Specifies gem version of Rails to use when vendor/rails is not present
+RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
+
+# Bootstrap the Rails environment, frameworks, and default configuration
+require File.join(File.dirname(__FILE__), 'boot')
+
+Rails::Initializer.run do |config|
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+
+ # Add additional load paths for your own custom dirs
+ # config.load_paths += %W( #{RAILS_ROOT}/extras )
+
+ # Specify gems that this application depends on and have them installed with rake gems:install
+ # config.gem "bj"
+ # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
+ # config.gem "sqlite3-ruby", :lib => "sqlite3"
+ # config.gem "aws-s3", :lib => "aws/s3"
+ config.gem "basic_assumption"
+
+ # Only load the plugins named here, in the order given (default is alphabetical).
+ # :all can be used as a placeholder for all plugins not explicitly named
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
+
+ # Skip frameworks you're not going to use. To use Rails without a database,
+ # you must remove the Active Record framework.
+ # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
+
+ # Activate observers that should always be running
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
+
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
+ # Run "rake -D time" for a list of tasks for finding time zone names.
+ config.time_zone = 'UTC'
+
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
+ # config.i18n.default_locale = :de
+end
@@ -0,0 +1,5 @@
+generate('resource widget name:string')
+generate('resource derived_widget')
+
+run('rake db:migrate')
+run('rake db:test:prepare')

0 comments on commit 3d32320

Please sign in to comment.