2014-10-26 20:52:55 -04:00
|
|
|
require 'acceptance_spec_helper'
|
|
|
|
|
|
|
|
describe 'shoulda-matchers integrates with Rails' do
|
|
|
|
before do
|
|
|
|
create_rails_application
|
|
|
|
|
|
|
|
write_file 'db/migrate/1_create_users.rb', <<-FILE
|
2017-09-28 01:50:32 -04:00
|
|
|
class CreateUsers < #{migration_class_name}
|
2014-10-26 20:52:55 -04:00
|
|
|
def self.up
|
|
|
|
create_table :users do |t|
|
|
|
|
t.string :name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
FILE
|
|
|
|
|
2015-05-07 00:43:35 -04:00
|
|
|
run_rake_tasks!(*%w(db:drop db:create db:migrate))
|
2014-10-26 20:52:55 -04:00
|
|
|
|
|
|
|
write_file 'app/models/user.rb', <<-FILE
|
|
|
|
class User < ActiveRecord::Base
|
|
|
|
validates_presence_of :name
|
|
|
|
end
|
|
|
|
FILE
|
|
|
|
|
|
|
|
write_file 'app/controllers/examples_controller.rb', <<-FILE
|
|
|
|
class ExamplesController < ApplicationController
|
|
|
|
def show
|
|
|
|
@example = 'hello'
|
2017-09-26 18:19:44 -04:00
|
|
|
head :ok
|
2014-10-26 20:52:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
FILE
|
|
|
|
|
|
|
|
configure_routes_with_single_wildcard_route
|
|
|
|
end
|
|
|
|
|
2014-10-22 20:54:36 -04:00
|
|
|
specify 'in a project that uses the default test framework' do
|
2014-10-26 20:52:55 -04:00
|
|
|
updating_bundle do
|
|
|
|
add_gems_for_n_unit
|
2014-10-22 20:54:36 -04:00
|
|
|
add_shoulda_matchers_to_project(
|
|
|
|
test_frameworks: [default_test_framework],
|
2015-05-07 00:43:35 -04:00
|
|
|
libraries: [:rails]
|
2014-10-22 20:54:36 -04:00
|
|
|
)
|
2014-10-26 20:52:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
run_tests_for_n_unit
|
|
|
|
end
|
|
|
|
|
|
|
|
specify 'in a project that uses RSpec' do
|
|
|
|
updating_bundle do
|
|
|
|
add_gems_for_rspec
|
2014-10-22 20:54:36 -04:00
|
|
|
add_shoulda_matchers_to_project(
|
|
|
|
test_frameworks: [:rspec],
|
2015-05-07 00:43:35 -04:00
|
|
|
libraries: [:rails]
|
2014-10-22 20:54:36 -04:00
|
|
|
)
|
2014-10-26 20:52:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
run_tests_for_rspec
|
|
|
|
end
|
|
|
|
|
|
|
|
specify 'in a project that uses Spring' do
|
|
|
|
unless bundle_includes?('spring')
|
|
|
|
skip "Spring isn't a dependency of this Appraisal"
|
|
|
|
end
|
|
|
|
|
|
|
|
updating_bundle do
|
|
|
|
add_spring_to_project
|
|
|
|
add_gems_for_rspec
|
2014-11-05 16:29:19 -05:00
|
|
|
add_shoulda_matchers_to_project(
|
|
|
|
test_frameworks: [:rspec],
|
2015-05-07 00:43:35 -04:00
|
|
|
libraries: [:rails],
|
2014-11-05 16:29:19 -05:00
|
|
|
manually: true
|
|
|
|
)
|
2014-10-26 20:52:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
run_command_within_bundle!('spring stop')
|
|
|
|
|
|
|
|
run_tests_for_rspec
|
|
|
|
end
|
|
|
|
|
|
|
|
specify 'in a project that combines both RSpec and Test::Unit' do
|
|
|
|
updating_bundle do
|
|
|
|
add_gems_for_n_unit
|
|
|
|
add_gems_for_rspec
|
2014-10-22 20:54:36 -04:00
|
|
|
add_shoulda_matchers_to_project(
|
|
|
|
test_frameworks: [:rspec, nil],
|
2015-05-07 00:43:35 -04:00
|
|
|
libraries: [:rails]
|
2014-10-22 20:54:36 -04:00
|
|
|
)
|
2014-10-26 20:52:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
run_tests_for_n_unit
|
|
|
|
run_tests_for_rspec
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_gems_for_n_unit
|
|
|
|
add_gem 'shoulda-context'
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_gems_for_rspec
|
|
|
|
add_rspec_rails_to_project!
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_tests_for_n_unit
|
|
|
|
write_file 'test/unit/user_test.rb', <<-FILE
|
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class UserTest < ActiveSupport::TestCase
|
|
|
|
should validate_presence_of(:name)
|
|
|
|
end
|
|
|
|
FILE
|
|
|
|
|
|
|
|
write_file 'test/functional/examples_controller_test.rb', <<-FILE
|
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class ExamplesControllerTest < ActionController::TestCase
|
|
|
|
def setup
|
|
|
|
get :show
|
|
|
|
end
|
|
|
|
|
|
|
|
should respond_with(:success)
|
|
|
|
end
|
|
|
|
FILE
|
|
|
|
|
|
|
|
result = run_n_unit_test_suite
|
|
|
|
|
|
|
|
expect(result).to indicate_that_tests_were_run(unit: 1, functional: 1)
|
2015-12-13 18:52:58 -05:00
|
|
|
expect(result).to have_output(
|
|
|
|
'User should validate that :name cannot be empty/falsy'
|
|
|
|
)
|
2014-10-26 20:52:55 -04:00
|
|
|
expect(result).to have_output('should respond with 200')
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_tests_for_rspec
|
2014-11-05 16:29:19 -05:00
|
|
|
add_rspec_file 'spec/models/user_spec.rb', <<-FILE
|
2014-10-26 20:52:55 -04:00
|
|
|
describe User do
|
|
|
|
it { should validate_presence_of(:name) }
|
|
|
|
end
|
|
|
|
FILE
|
|
|
|
|
2014-11-05 16:29:19 -05:00
|
|
|
add_rspec_file 'spec/controllers/examples_controller_spec.rb', <<-FILE
|
2014-10-26 20:52:55 -04:00
|
|
|
describe ExamplesController, "show" do
|
|
|
|
before { get :show }
|
|
|
|
|
|
|
|
it { should respond_with(:success) }
|
|
|
|
end
|
|
|
|
FILE
|
|
|
|
|
|
|
|
result = run_rspec_suite
|
|
|
|
|
|
|
|
expect(result).to have_output('2 examples, 0 failures')
|
2015-12-13 18:52:58 -05:00
|
|
|
expect(result).to have_output(
|
|
|
|
'should validate that :name cannot be empty/falsy'
|
|
|
|
)
|
2014-10-26 20:52:55 -04:00
|
|
|
expect(result).to have_output('should respond with 200')
|
|
|
|
end
|
|
|
|
end
|