Skip to content

Commit

Permalink
Got cucumber features passing with aruba and extracted context framework
Browse files Browse the repository at this point in the history
  • Loading branch information
jferris committed Jan 19, 2011
1 parent e7eee1a commit edaa699
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 153 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -6,4 +6,5 @@ gem 'mocha'
gem 'rspec-rails'
gem 'ruby-debug'
gem 'cucumber'
gem "aruba"

5 changes: 5 additions & 0 deletions Gemfile.lock
Expand Up @@ -29,6 +29,10 @@ GEM
activesupport (= 3.0.3)
activesupport (3.0.3)
arel (2.0.6)
aruba (0.2.7)
background_process
cucumber (~> 0.10.0)
background_process (1.2)
builder (2.1.2)
columnize (0.3.2)
cucumber (0.10.0)
Expand Down Expand Up @@ -103,6 +107,7 @@ PLATFORMS
ruby

DEPENDENCIES
aruba
cucumber
mocha
rails (= 3.0.3)
Expand Down
1 change: 0 additions & 1 deletion Rakefile
Expand Up @@ -43,7 +43,6 @@ task :clobber => [:clobber_rdoc, :clobber_package]
Cucumber::Rake::Task.new do |t|
t.fork = true
t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'progress')]
t.profile = 'default'
end

desc 'Default: run specs and cucumber features'
Expand Down
1 change: 0 additions & 1 deletion cucumber.yml

This file was deleted.

40 changes: 20 additions & 20 deletions features/rails_integration.feature
@@ -1,8 +1,9 @@
@disable-bundler
Feature: integrate with Rails

Background:
When I generate a new rails application
And I save the following as "db/migrate/1_create_users.rb"
And I write to "db/migrate/1_create_users.rb" with:
"""
class CreateUsers < ActiveRecord::Migration
def self.up
Expand All @@ -12,14 +13,14 @@ Feature: integrate with Rails
end
end
"""
When I run "rake db:migrate"
And I save the following as "app/models/user.rb"
When I successfully run "rake db:migrate --trace"
And I write to "app/models/user.rb" with:
"""
class User < ActiveRecord::Base
validates_presence_of :name
end
"""
When I save the following as "app/controllers/examples_controller.rb"
When I write to "app/controllers/examples_controller.rb" with:
"""
class ExamplesController < ApplicationController
def show
Expand All @@ -31,16 +32,17 @@ Feature: integrate with Rails
When I configure a wildcard route

Scenario: generate a rails application and use matchers in Test::Unit
When I configure the application to use "shoulda" from this project
And I save the following as "test/unit/user_test.rb"
When I configure the application to use shoulda-context
And I configure the application to use "shoulda" from this project
And I write to "test/unit/user_test.rb" with:
"""
require 'test_helper'
class UserTest < ActiveSupport::TestCase
should validate_presence_of(:name)
end
"""
When I save the following as "test/functional/examples_controller_test.rb"
When I write to "test/functional/examples_controller_test.rb" with:
"""
require 'test_helper'
Expand All @@ -53,36 +55,34 @@ Feature: integrate with Rails
should assign_to(:example)
end
"""
When I run "rake test TESTOPTS=-v"
Then I should see "1 tests, 1 assertions, 0 failures, 0 errors"
And I should see "2 tests, 2 assertions, 0 failures, 0 errors"
And I should see "User should require name to be set"
And I should see "ExamplesController should assign @example"
When I successfully run "rake test TESTOPTS=-v --trace"
Then the output should contain "1 tests, 1 assertions, 0 failures, 0 errors"
And the output should contain "2 tests, 2 assertions, 0 failures, 0 errors"
And the output should contain "User should require name to be set"
And the output should contain "ExamplesController should assign @example"

Scenario: generate a rails application and use matchers in Rspec
When I configure the application to use rspec-rails
And I configure the application to use "shoulda" from this project
And I run the rspec generator
And I save the following as "spec/models/user_spec.rb"
And I write to "spec/models/user_spec.rb" with:
"""
require 'spec_helper'
describe User do
it { should validate_presence_of(:name) }
end
"""
When I save the following as "spec/controllers/examples_controller_spec.rb"
When I write to "spec/controllers/examples_controller_spec.rb" with:
"""
require 'spec_helper'
describe ExamplesController, "show" do
before { get :show }
# rspec2 doesn't use the controller as the subject
subject { controller }
it { should assign_to(:example) }
end
"""
When I run "rake spec SPEC_OPTS=-fs"
Then I should see "2 examples, 0 failures"
And I should see "should require name to be set"
And I should see "should assign @example"
When I successfully run "rake spec SPEC_OPTS=-fs --trace"
Then the output should contain "2 examples, 0 failures"
And the output should contain "should require name to be set"
And the output should contain "should assign @example"
31 changes: 0 additions & 31 deletions features/step_definitions/common_steps.rb

This file was deleted.

60 changes: 0 additions & 60 deletions features/step_definitions/rails3_steps.rb

This file was deleted.

65 changes: 65 additions & 0 deletions features/step_definitions/rails_steps.rb
@@ -0,0 +1,65 @@
PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')).freeze
APP_NAME = 'testapp'.freeze

When /^I generate a new rails application$/ do
steps %{
When I run "rails _3.0.3_ new #{APP_NAME}"
And I cd to "#{APP_NAME}"
And I write to "Gemfile" with:
"""
source "http://rubygems.org"
gem 'rails', '3.0.3'
gem 'sqlite3-ruby', :require => 'sqlite3'
"""
And I successfully run "bundle install --local"
}
end

When /^I configure the application to use "([^\"]+)" from this project$/ do |name|
append_to_gemfile "gem '#{name}', :path => '#{PROJECT_ROOT}'"
steps %{And I run "bundle install --local"}
end

When /^I run the rspec generator$/ do
steps %{
When I successfully run "rails generate rspec:install"
}
end

When /^I configure the application to use rspec\-rails$/ do
append_to_gemfile "gem 'rspec-rails'"
steps %{And I run "bundle install --local"}
end

When /^I configure the application to use shoulda-context$/ do
append_to_gemfile "gem 'shoulda-context', :git => 'git@github.com:thoughtbot/shoulda-context.git'"
steps %{And I run "bundle install --local"}
end

When /^I configure a wildcard route$/ do
steps %{
When I write to "config/routes.rb" with:
"""
Rails.application.routes.draw do
match ':controller(/:action(/:id(.:format)))'
end
"""
}
end

module AppendHelpers
def append_to(path, contents)
in_current_dir do
File.open(path, "a") do |file|
file.puts
file.puts contents
end
end
end

def append_to_gemfile(contents)
append_to('Gemfile', contents)
end
end

World(AppendHelpers)
2 changes: 2 additions & 0 deletions features/support/env.rb
@@ -0,0 +1,2 @@
require 'aruba/cucumber'

36 changes: 0 additions & 36 deletions features/support/terminal.rb

This file was deleted.

4 changes: 2 additions & 2 deletions lib/shoulda/integrations/rspec.rb
Expand Up @@ -9,14 +9,14 @@ module RSpec::Matchers

if defined?(::ActionController)
require 'shoulda/action_controller'
module Rails::ControllerExampleGroup
module RSpec::Rails::ControllerExampleGroup
include Shoulda::ActionController
end
end

if defined?(::ActionMailer)
require 'shoulda/action_mailer'
module Rails::MailerExampleGroup
module RSpec::Rails::MailerExampleGroup
include Shoulda::ActionMailer
end
end
Expand Down
2 changes: 0 additions & 2 deletions shoulda.gemspec
Expand Up @@ -9,9 +9,7 @@ Gem::Specification.new do |s|
s.authors = ["Tammer Saleh", "Joe Ferris", "Ryan McGeary", "Dan Croak",
"Matt Jankowski"]
s.date = Time.now.strftime("%Y-%m-%d")
s.default_executable = %q{convert_to_should_syntax}
s.email = %q{support@thoughtbot.com}
s.executables = ["convert_to_should_syntax"]
s.extra_rdoc_files = ["README.rdoc", "CONTRIBUTION_GUIDELINES.rdoc"]
s.files = Dir["[A-Z]*", "{bin,lib,rails,test}/**/*"]
s.homepage = %q{http://thoughtbot.com/community/}
Expand Down

0 comments on commit edaa699

Please sign in to comment.