1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00

Got cucumber features passing with aruba and extracted context framework

This commit is contained in:
Joe Ferris 2010-12-14 21:11:38 -05:00
parent 2037e969dc
commit ecb01a209d
12 changed files with 95 additions and 153 deletions

View file

@ -6,4 +6,5 @@ gem 'mocha'
gem 'rspec-rails'
gem 'ruby-debug'
gem 'cucumber'
gem "aruba"

View file

@ -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)
@ -103,6 +107,7 @@ PLATFORMS
ruby
DEPENDENCIES
aruba
cucumber
mocha
rails (= 3.0.3)

View file

@ -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'

View file

@ -1 +0,0 @@
default: -r features/support -r features/step_definitions/common_steps.rb -r features/step_definitions/rails3_steps.rb

View file

@ -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
@ -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
@ -31,8 +32,9 @@ 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'
@ -40,7 +42,7 @@ Feature: integrate with Rails
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'
@ -53,17 +55,17 @@ 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'
@ -71,18 +73,16 @@ Feature: integrate with Rails
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"

View file

@ -1,31 +0,0 @@
PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')).freeze
TEMP_ROOT = File.join(PROJECT_ROOT, 'tmp').freeze
APP_NAME = 'testapp'.freeze
RAILS_ROOT = File.join(TEMP_ROOT, APP_NAME).freeze
Before do
FileUtils.rm_rf(TEMP_ROOT)
FileUtils.mkdir_p(TEMP_ROOT)
@terminal = Terminal.new
end
After do
FileUtils.rm_f(File.join(PROJECT_ROOT, '.specification'))
end
When /^I save the following as "([^\"]*)"$/ do |path, string|
FileUtils.mkdir_p(File.join(RAILS_ROOT, File.dirname(path)))
File.open(File.join(RAILS_ROOT, path), 'w') { |file| file.write(string) }
end
When /^I run "([^\"]*)"$/ do |command|
@terminal.cd(RAILS_ROOT)
@terminal.run(command)
end
Then /^I should see "([^\"]*)"$/ do |expected_text|
unless @terminal.output.include?(expected_text)
raise("Got terminal output:\n#{@terminal.output}\n\nExpected output:\n#{expected_text}")
end
end

View file

@ -1,60 +0,0 @@
When /^I generate a new rails application$/ do
@terminal.cd(TEMP_ROOT)
@terminal.run("rails _3.0.3_ new #{APP_NAME}")
steps %{
When I save the following as "Gemfile"
"""
source "http://rubygems.org"
gem 'rails', '3.0.3'
gem 'sqlite3-ruby', :require => 'sqlite3'
"""
}
end
When /^I configure the application to use "([^\"]+)" from this project$/ do |name|
append_to_gemfile "gem '#{name}', :path => '../../'"
steps %{And I run "bundle install"}
end
When /^I run the "([^"]*)" generator$/ do |name|
steps %{
When I run "./script/rails generate #{name}"
}
end
When /^I run the rspec generator$/ do
steps %{
When I run the "rspec:install" generator
}
end
When /^I configure the application to use rspec\-rails$/ do
append_to_gemfile "gem 'rspec-rails'"
steps %{And I run "bundle install"}
end
When /^I configure a wildcard route$/ do
steps %{
When I save the following as "config/routes.rb"
"""
Rails.application.routes.draw do |map|
match ':controller(/:action(/:id(.:format)))'
end
"""
}
end
module AppendHelpers
def append_to(path, contents)
File.open(path, "a") do |file|
file.puts
file.puts contents
end
end
def append_to_gemfile(contents)
append_to(File.join(RAILS_ROOT, 'Gemfile'), contents)
end
end
World(AppendHelpers)

View file

@ -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
features/support/env.rb Normal file
View file

@ -0,0 +1,2 @@
require 'aruba/cucumber'

View file

@ -1,36 +0,0 @@
require 'fileutils'
class Terminal
attr_reader :output, :status
def initialize
@cwd = FileUtils.pwd
@output = ""
@status = 0
@logger = Logger.new(File.join(TEMP_ROOT, 'terminal.log'))
end
def cd(directory)
@cwd = directory
end
def run(command)
output << "#{command}\n"
FileUtils.cd(@cwd) do
logger.debug(command)
result = `#{command} 2>&1`
logger.debug(result)
output << result
end
@status = $?
end
def echo(string)
logger.debug(string)
end
private
attr_reader :logger
end

View file

@ -9,14 +9,14 @@ end
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

View file

@ -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/}