2010-06-23 18:29:51 +00:00
|
|
|
Feature: integrate with Rails
|
|
|
|
|
|
|
|
Background:
|
|
|
|
When I generate a new rails application
|
2010-12-15 02:11:38 +00:00
|
|
|
And I write to "db/migrate/1_create_users.rb" with:
|
2010-06-23 18:29:51 +00:00
|
|
|
"""
|
|
|
|
class CreateUsers < ActiveRecord::Migration
|
|
|
|
def self.up
|
|
|
|
create_table :users do |t|
|
|
|
|
t.string :name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
"""
|
2011-05-25 18:38:07 +00:00
|
|
|
When I successfully run `bundle exec rake db:migrate --trace`
|
2010-12-15 02:11:38 +00:00
|
|
|
And I write to "app/models/user.rb" with:
|
2010-06-23 18:29:51 +00:00
|
|
|
"""
|
|
|
|
class User < ActiveRecord::Base
|
|
|
|
validates_presence_of :name
|
|
|
|
end
|
|
|
|
"""
|
2010-12-15 02:11:38 +00:00
|
|
|
When I write to "app/controllers/examples_controller.rb" with:
|
2010-06-23 18:29:51 +00:00
|
|
|
"""
|
|
|
|
class ExamplesController < ApplicationController
|
|
|
|
def show
|
|
|
|
@example = 'hello'
|
|
|
|
render :nothing => true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
"""
|
|
|
|
When I configure a wildcard route
|
|
|
|
|
|
|
|
Scenario: generate a rails application and use matchers in Test::Unit
|
2010-12-15 02:11:38 +00:00
|
|
|
When I configure the application to use shoulda-context
|
2010-12-15 22:34:19 +00:00
|
|
|
And I configure the application to use "shoulda-matchers" from this project
|
2010-12-15 02:11:38 +00:00
|
|
|
And I write to "test/unit/user_test.rb" with:
|
2010-06-23 18:29:51 +00:00
|
|
|
"""
|
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class UserTest < ActiveSupport::TestCase
|
|
|
|
should validate_presence_of(:name)
|
|
|
|
end
|
|
|
|
"""
|
2010-12-15 02:11:38 +00:00
|
|
|
When I write to "test/functional/examples_controller_test.rb" with:
|
2010-06-23 18:29:51 +00:00
|
|
|
"""
|
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class ExamplesControllerTest < ActionController::TestCase
|
|
|
|
def setup
|
|
|
|
get :show
|
|
|
|
end
|
|
|
|
|
|
|
|
should respond_with(:success)
|
|
|
|
end
|
|
|
|
"""
|
2011-09-18 14:39:18 +00:00
|
|
|
When I set the "TESTOPTS" environment variable to "-v"
|
|
|
|
When I successfully run `bundle exec rake test --trace`
|
2013-07-12 19:44:17 +00:00
|
|
|
Then the output should indicate that 1 unit and 1 functional test were run
|
2010-12-15 02:11:38 +00:00
|
|
|
And the output should contain "User should require name to be set"
|
2013-03-15 22:06:28 +00:00
|
|
|
And the output should contain "should respond with 200"
|
2010-06-23 18:29:51 +00:00
|
|
|
|
|
|
|
Scenario: generate a rails application and use matchers in Rspec
|
2013-03-20 16:38:45 +00:00
|
|
|
When I configure the application to use rspec-rails
|
2010-12-15 22:34:19 +00:00
|
|
|
And I configure the application to use "shoulda-matchers" from this project
|
2010-06-23 18:29:51 +00:00
|
|
|
And I run the rspec generator
|
2010-12-15 02:11:38 +00:00
|
|
|
And I write to "spec/models/user_spec.rb" with:
|
2010-06-23 18:29:51 +00:00
|
|
|
"""
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe User do
|
|
|
|
it { should validate_presence_of(:name) }
|
|
|
|
end
|
|
|
|
"""
|
2010-12-15 02:11:38 +00:00
|
|
|
When I write to "spec/controllers/examples_controller_spec.rb" with:
|
2010-06-23 18:29:51 +00:00
|
|
|
"""
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe ExamplesController, "show" do
|
|
|
|
before { get :show }
|
2013-03-15 22:06:28 +00:00
|
|
|
it { should respond_with(:success) }
|
2010-06-23 18:29:51 +00:00
|
|
|
end
|
|
|
|
"""
|
2011-05-25 18:38:07 +00:00
|
|
|
When I successfully run `bundle exec rake spec SPEC_OPTS=-fs --trace`
|
2010-12-15 02:11:38 +00:00
|
|
|
Then the output should contain "2 examples, 0 failures"
|
|
|
|
And the output should contain "should require name to be set"
|
2013-03-15 22:06:28 +00:00
|
|
|
And the output should contain "should respond with 200"
|
2012-07-11 10:17:04 +00:00
|
|
|
|
|
|
|
Scenario: generate a Rails application that mixes Rspec and Test::Unit
|
2013-03-20 16:38:45 +00:00
|
|
|
When I configure the application to use rspec-rails in test and development
|
2012-07-11 10:17:04 +00:00
|
|
|
And I configure the application to use "shoulda-matchers" from this project in test and development
|
|
|
|
And I run the rspec generator
|
|
|
|
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 write to "test/functional/examples_controller_test.rb" with:
|
|
|
|
"""
|
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class ExamplesControllerTest < ActionController::TestCase
|
2013-03-15 22:06:28 +00:00
|
|
|
test 'responds successfully' do
|
2012-07-11 10:17:04 +00:00
|
|
|
get :show
|
2013-03-15 22:06:28 +00:00
|
|
|
assert respond_with(:success)
|
2012-07-11 10:17:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
"""
|
|
|
|
When I successfully run `bundle exec rake spec test:functionals SPEC_OPTS=-fs --trace`
|
|
|
|
Then the output should contain "1 example, 0 failures"
|
2013-07-12 19:44:17 +00:00
|
|
|
Then the output should indicate that 1 test was run
|