-
-
Notifications
You must be signed in to change notification settings - Fork 910
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make independent matchers really independent
Why: * When `delegate_method` was modified a while back to add Doublespeak and use MatcherContext, Shoulda::Matchers::Independent became unable to be required independently. To satisfy the above: * Require Doublespeak and MatcherContext within `delegate_method_matcher.rb`. * Add an acceptance test to ensure that Independent stays independent. Secondary-Author: jc00ke <jesse@jc00ke.com>
- Loading branch information
Showing
9 changed files
with
173 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,125 @@ | ||
require 'acceptance_spec_helper' | ||
|
||
describe 'shoulda-matchers has independent matchers' do | ||
context '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], | ||
manually: true | ||
) | ||
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], | ||
manually: true | ||
) | ||
end | ||
|
||
write_file 'lib/post_office.rb', <<-FILE | ||
class PostOffice | ||
end | ||
FILE | ||
|
||
write_file 'lib/courier.rb', <<-FILE | ||
require 'forwardable' | ||
write_file 'lib/post_office.rb', <<-FILE | ||
class PostOffice | ||
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 | ||
end | ||
FILE | ||
end | ||
|
||
write_file 'lib/courier.rb', <<-FILE | ||
require 'forwardable' | ||
result = run_n_unit_tests('test/courier_test.rb') | ||
|
||
class Courier | ||
extend Forwardable | ||
expect(result).to indicate_number_of_tests_was_run(1) | ||
expect(result).to have_output( | ||
'Courier should delegate #deliver to #post_office object' | ||
) | ||
end | ||
|
||
def_delegators :post_office, :deliver | ||
specify 'and integrates with a Ruby application that uses RSpec' do | ||
create_generic_bundler_project | ||
|
||
attr_reader :post_office | ||
updating_bundle do | ||
add_rspec_to_project | ||
add_shoulda_matchers_to_project( | ||
manually: true, | ||
with_configuration: false | ||
) | ||
write_file 'spec/spec_helper.rb', <<-FILE | ||
require 'shoulda/matchers/independent' | ||
def initialize(post_office) | ||
@post_office = post_office | ||
end | ||
RSpec.configure do |config| | ||
config.include(Shoulda::Matchers::Independent) | ||
end | ||
FILE | ||
end | ||
|
||
write_file 'lib/post_office.rb', <<-FILE | ||
class PostOffice | ||
end | ||
FILE | ||
|
||
write_n_unit_test 'test/courier_test.rb' do |test_case_superclass| | ||
<<-FILE | ||
require 'test_helper' | ||
require 'courier' | ||
require 'post_office' | ||
write_file 'lib/courier.rb', <<-FILE | ||
require 'forwardable' | ||
class CourierTest < #{test_case_superclass} | ||
subject { Courier.new(post_office) } | ||
class Courier | ||
extend Forwardable | ||
should delegate_method(:deliver).to(:post_office) | ||
def_delegators :post_office, :deliver | ||
def post_office | ||
PostOffice.new | ||
end | ||
end | ||
FILE | ||
attr_reader :post_office | ||
def initialize(post_office) | ||
@post_office = post_office | ||
end | ||
end | ||
FILE | ||
|
||
result = run_n_unit_tests('test/courier_test.rb') | ||
write_file 'spec/courier_spec.rb', <<-FILE | ||
require 'spec_helper' | ||
require 'courier' | ||
require 'post_office' | ||
expect(result).to indicate_number_of_tests_was_run(1) | ||
expect(result).to have_output( | ||
'Courier should delegate #deliver to #post_office object' | ||
) | ||
end | ||
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( | ||
/Courier\s+should delegate #deliver to #post_office object/ | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters