Skip to content

Commit df249eb

Browse files
committed
extract assert_snapshot_unchanged_on_pass
... to DRY up assert_snapshot_unchanged + run_as_test + assert_passed combo
1 parent e05c9c4 commit df249eb

File tree

3 files changed

+18
-26
lines changed

3 files changed

+18
-26
lines changed

test/acceptance/acceptance_test_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,9 @@ def teardown_acceptance_test
3838
Mocha::Configuration.reset_configuration
3939
end
4040

41+
def assert_snapshot_unchanged_on_pass(object, &block)
42+
assert_snapshot_unchanged(object) { assert_passed(run_as_test(&block)) }
43+
end
44+
4145
include Introspection::Assertions
4246
end

test/acceptance/prepend_test.rb

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,37 +47,28 @@ def my_method
4747
end
4848

4949
def test_stubbing_any_instance_with_multiple_prepended_methods
50-
assert_snapshot_unchanged(Klass1) do
51-
test_result = run_as_test do
52-
Klass1.any_instance.stubs(:my_method).returns('Bye World')
53-
assert_equal 'Bye World', Klass1.new.my_method
54-
end
55-
assert_passed(test_result)
50+
assert_snapshot_unchanged_on_pass(Klass1) do
51+
Klass1.any_instance.stubs(:my_method).returns('Bye World')
52+
assert_equal 'Bye World', Klass1.new.my_method
5653
end
5754
assert_equal 'Hello World Wide', Klass1.new.my_method
5855
end
5956

6057
def test_stubbing_instance_with_multiple_prepended_methods
6158
object = Klass1.new
6259

63-
assert_snapshot_unchanged(object) do
64-
test_result = run_as_test do
65-
object.stubs(:my_method).returns('Bye World')
66-
assert_equal 'Bye World', object.my_method
67-
assert_equal 'Hello World Wide', Klass1.new.my_method
68-
end
69-
assert_passed(test_result)
60+
assert_snapshot_unchanged_on_pass(object) do
61+
object.stubs(:my_method).returns('Bye World')
62+
assert_equal 'Bye World', object.my_method
63+
assert_equal 'Hello World Wide', Klass1.new.my_method
7064
end
7165
assert_equal 'Hello World Wide', object.my_method
7266
end
7367

7468
def test_stubbing_a_prepended_class_method
75-
assert_snapshot_unchanged(Klass2) do
76-
test_result = run_as_test do
77-
Klass2.stubs(:my_method).returns('Bye World')
78-
assert_equal 'Bye World', Klass2.my_method
79-
end
80-
assert_passed(test_result)
69+
assert_snapshot_unchanged_on_pass(Klass2) do
70+
Klass2.stubs(:my_method).returns('Bye World')
71+
assert_equal 'Bye World', Klass2.my_method
8172
end
8273
assert_equal 'Hello World Wide', Klass2.my_method
8374
end

test/acceptance/stub_method_shared_tests.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,10 @@ def assert_snapshot_unchanged_on_stubbing(visibility)
3232
instance = stubbed_instance
3333
stub_owner_in_scope = stub_owner || instance
3434
method = alias_method? ? :my_aliased_method : stubbed_method_name
35-
assert_snapshot_unchanged(instance) do
36-
test_result = run_as_test do
37-
stub_owner_in_scope.stubs(method).returns(:new_return_value)
38-
assert_method_visibility instance, method, visibility
39-
assert_equal :new_return_value, instance.send(method)
40-
end
41-
assert_passed(test_result)
35+
assert_snapshot_unchanged_on_pass(instance) do
36+
stub_owner_in_scope.stubs(method).returns(:new_return_value)
37+
assert_method_visibility instance, method, visibility
38+
assert_equal :new_return_value, instance.send(method)
4239
end
4340
assert_equal :original_return_value, instance.send(method)
4441
end

0 commit comments

Comments
 (0)