2014-10-26 18:52:55 -06:00
|
|
|
require 'acceptance_spec_helper'
|
|
|
|
|
2015-07-01 14:21:03 -07:00
|
|
|
describe 'shoulda-matchers has independent matchers, specifically delegate_method' do
|
|
|
|
specify 'and integrates with a Ruby application that uses the default test framework' do
|
|
|
|
create_generic_bundler_project
|
|
|
|
|
|
|
|
updating_bundle do
|
|
|
|
add_minitest_to_project
|
|
|
|
add_shoulda_context_to_project(manually: true)
|
|
|
|
add_shoulda_matchers_to_project(
|
|
|
|
test_frameworks: [default_test_framework],
|
2020-01-01 12:20:50 -08:00
|
|
|
manually: true,
|
2015-07-01 14:21:03 -07:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
write_file 'lib/post_office.rb', <<-FILE
|
|
|
|
class PostOffice
|
2014-11-05 14:29:19 -07:00
|
|
|
end
|
2015-07-01 14:21:03 -07:00
|
|
|
FILE
|
|
|
|
|
|
|
|
write_file 'lib/courier.rb', <<-FILE
|
|
|
|
require 'forwardable'
|
2014-10-26 18:52:55 -06:00
|
|
|
|
2015-07-01 14:21:03 -07:00
|
|
|
class Courier
|
|
|
|
extend Forwardable
|
|
|
|
|
|
|
|
def_delegators :post_office, :deliver
|
|
|
|
|
|
|
|
attr_reader :post_office
|
|
|
|
|
|
|
|
def initialize(post_office)
|
|
|
|
@post_office = post_office
|
|
|
|
end
|
|
|
|
end
|
|
|
|
FILE
|
|
|
|
|
|
|
|
write_n_unit_test 'test/courier_test.rb' do |test_case_superclass|
|
|
|
|
<<-FILE
|
|
|
|
require 'test_helper'
|
|
|
|
require 'courier'
|
|
|
|
require 'post_office'
|
|
|
|
|
|
|
|
class CourierTest < #{test_case_superclass}
|
|
|
|
subject { Courier.new(post_office) }
|
|
|
|
|
|
|
|
should delegate_method(:deliver).to(:post_office)
|
|
|
|
|
|
|
|
def post_office
|
|
|
|
PostOffice.new
|
|
|
|
end
|
2014-10-26 18:52:55 -06:00
|
|
|
end
|
|
|
|
FILE
|
2015-07-01 14:21:03 -07:00
|
|
|
end
|
2014-10-26 18:52:55 -06:00
|
|
|
|
2019-11-19 03:45:13 +01:00
|
|
|
result = run_n_unit_tests('test/courier_test.rb - -v')
|
2014-10-26 18:52:55 -06:00
|
|
|
|
2015-07-01 14:21:03 -07:00
|
|
|
expect(result).to indicate_number_of_tests_was_run(1)
|
|
|
|
expect(result).to have_output(
|
2020-01-01 12:20:50 -08:00
|
|
|
'Courier should delegate #deliver to the #post_office object',
|
2015-07-01 14:21:03 -07:00
|
|
|
)
|
|
|
|
end
|
2014-10-26 18:52:55 -06:00
|
|
|
|
2015-07-01 14:21:03 -07:00
|
|
|
specify 'and integrates with a Ruby application that uses RSpec' do
|
|
|
|
create_generic_bundler_project
|
2014-10-26 18:52:55 -06:00
|
|
|
|
2015-07-01 14:21:03 -07:00
|
|
|
updating_bundle do
|
|
|
|
add_rspec_to_project
|
|
|
|
add_shoulda_matchers_to_project(
|
|
|
|
manually: true,
|
2020-01-01 12:20:50 -08:00
|
|
|
with_configuration: false,
|
2015-07-01 14:21:03 -07:00
|
|
|
)
|
|
|
|
write_file 'spec/spec_helper.rb', <<-FILE
|
|
|
|
require 'shoulda/matchers/independent'
|
2014-10-26 18:52:55 -06:00
|
|
|
|
2015-07-01 14:21:03 -07:00
|
|
|
RSpec.configure do |config|
|
|
|
|
config.include(Shoulda::Matchers::Independent)
|
2014-10-26 18:52:55 -06:00
|
|
|
end
|
|
|
|
FILE
|
2015-07-01 14:21:03 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
write_file 'lib/post_office.rb', <<-FILE
|
|
|
|
class PostOffice
|
|
|
|
end
|
|
|
|
FILE
|
2014-10-26 18:52:55 -06:00
|
|
|
|
2015-07-01 14:21:03 -07:00
|
|
|
write_file 'lib/courier.rb', <<-FILE
|
|
|
|
require 'forwardable'
|
2014-10-26 18:52:55 -06:00
|
|
|
|
2015-07-01 14:21:03 -07:00
|
|
|
class Courier
|
|
|
|
extend Forwardable
|
2014-10-26 18:52:55 -06:00
|
|
|
|
2015-07-01 14:21:03 -07:00
|
|
|
def_delegators :post_office, :deliver
|
2014-10-26 18:52:55 -06:00
|
|
|
|
2015-07-01 14:21:03 -07:00
|
|
|
attr_reader :post_office
|
|
|
|
|
|
|
|
def initialize(post_office)
|
|
|
|
@post_office = post_office
|
|
|
|
end
|
2014-10-26 18:52:55 -06:00
|
|
|
end
|
2015-07-01 14:21:03 -07:00
|
|
|
FILE
|
2014-10-26 18:52:55 -06:00
|
|
|
|
2015-07-01 14:21:03 -07:00
|
|
|
write_file 'spec/courier_spec.rb', <<-FILE
|
|
|
|
require 'spec_helper'
|
|
|
|
require 'courier'
|
|
|
|
require 'post_office'
|
2014-10-26 18:52:55 -06:00
|
|
|
|
2015-07-01 14:21:03 -07:00
|
|
|
describe Courier do
|
|
|
|
subject { Courier.new(post_office) }
|
|
|
|
|
|
|
|
it { should delegate_method(:deliver).to(:post_office) }
|
|
|
|
|
|
|
|
def post_office
|
|
|
|
PostOffice.new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
FILE
|
|
|
|
|
|
|
|
result = run_rspec_tests('spec/courier_spec.rb')
|
|
|
|
|
|
|
|
expect(result).to indicate_number_of_tests_was_run(1)
|
|
|
|
expect(result).to have_output(
|
2020-01-01 12:20:50 -08:00
|
|
|
/Courier\s+is expected to delegate #deliver to the #post_office object/,
|
2015-07-01 14:21:03 -07:00
|
|
|
)
|
2014-10-26 18:52:55 -06:00
|
|
|
end
|
|
|
|
end
|