bogus 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +53 -34
- data/Guardfile +3 -1
- data/Guardfile.cucumber +2 -0
- data/README.md +2 -1
- data/bogus.gemspec +1 -0
- data/features/.nav +2 -0
- data/features/changelog.md +8 -0
- data/features/contract_tests/custom_overwritten_class.feature +115 -0
- data/features/minitest_support.feature +228 -0
- data/lib/bogus.rb +3 -3
- data/lib/bogus/contracts/adds_contract_verification.rb +55 -0
- data/lib/bogus/{adds_recording.rb → contracts/adds_recording.rb} +2 -3
- data/lib/bogus/{contract_not_fulfilled.rb → contracts/contract_not_fulfilled.rb} +0 -0
- data/lib/bogus/{interactions_repository.rb → contracts/interactions_repository.rb} +0 -0
- data/lib/bogus/{proxy_class.rb → contracts/proxy_class.rb} +0 -0
- data/lib/bogus/{recording_proxy.rb → contracts/recording_proxy.rb} +0 -0
- data/lib/bogus/{records_double_interactions.rb → contracts/records_double_interactions.rb} +0 -0
- data/lib/bogus/{verifies_contracts.rb → contracts/verifies_contracts.rb} +0 -0
- data/lib/bogus/{active_record_accessors.rb → fakes/active_record_accessors.rb} +0 -0
- data/lib/bogus/fakes/base_class_identifier.rb +39 -0
- data/lib/bogus/{class_methods.rb → fakes/class_methods.rb} +0 -0
- data/lib/bogus/{constructor_methods.rb → fakes/constructor_methods.rb} +0 -0
- data/lib/bogus/{converts_name_to_class.rb → fakes/converts_name_to_class.rb} +0 -0
- data/lib/bogus/{copies_classes.rb → fakes/copies_classes.rb} +8 -0
- data/lib/bogus/{copies_methods.rb → fakes/copies_methods.rb} +0 -0
- data/lib/bogus/{creates_fakes.rb → fakes/creates_fakes.rb} +0 -0
- data/lib/bogus/{creates_fakes_with_stubbed_methods.rb → fakes/creates_fakes_with_stubbed_methods.rb} +0 -0
- data/lib/bogus/{fake.rb → fakes/fake.rb} +4 -12
- data/lib/bogus/{fake_registry.rb → fakes/fake_registry.rb} +0 -0
- data/lib/bogus/{fakes_classes.rb → fakes/fakes_classes.rb} +0 -0
- data/lib/bogus/{instance_methods.rb → fakes/instance_methods.rb} +0 -0
- data/lib/bogus/{makes_ducks.rb → fakes/makes_ducks.rb} +0 -0
- data/lib/bogus/{makes_substitute_methods.rb → fakes/makes_substitute_methods.rb} +0 -0
- data/lib/bogus/{makes_subtypes.rb → fakes/makes_subtypes.rb} +0 -0
- data/lib/bogus/{method_stringifier.rb → fakes/method_stringifier.rb} +0 -0
- data/lib/bogus/{overwriten_classes.rb → fakes/overwriten_classes.rb} +0 -0
- data/lib/bogus/{overwrites_classes.rb → fakes/overwrites_classes.rb} +0 -0
- data/lib/bogus/{registers_created_fakes.rb → fakes/registers_created_fakes.rb} +0 -0
- data/lib/bogus/{resets_overwritten_classes.rb → fakes/resets_overwritten_classes.rb} +0 -0
- data/lib/bogus/{responds_to_everything.rb → fakes/responds_to_everything.rb} +0 -0
- data/lib/bogus/injector.rb +4 -0
- data/lib/bogus/minitest.rb +10 -7
- data/lib/bogus/minitest/spec.rb +7 -0
- data/lib/bogus/minitest/syntax.rb +27 -0
- data/lib/bogus/public_methods.rb +4 -0
- data/lib/bogus/{rspec_adapter.rb → rspec/adapter.rb} +0 -0
- data/lib/bogus/rspec/extensions.rb +21 -0
- data/lib/bogus/rspec/syntax.rb +20 -0
- data/lib/bogus/{any_args.rb → stubbing/any_args.rb} +0 -0
- data/lib/bogus/{anything.rb → stubbing/anything.rb} +0 -0
- data/lib/bogus/{default_value.rb → stubbing/default_value.rb} +0 -0
- data/lib/bogus/{double.rb → stubbing/double.rb} +0 -0
- data/lib/bogus/{ensures_all_interactions_satisfied.rb → stubbing/ensures_all_interactions_satisfied.rb} +0 -0
- data/lib/bogus/{has_overwritten_methods.rb → stubbing/has_overwritten_methods.rb} +0 -0
- data/lib/bogus/{have_received_matcher.rb → stubbing/have_received_matcher.rb} +0 -0
- data/lib/bogus/{interaction.rb → stubbing/interaction.rb} +0 -0
- data/lib/bogus/{interaction_presenter.rb → stubbing/interaction_presenter.rb} +0 -0
- data/lib/bogus/{multi_stubber.rb → stubbing/multi_stubber.rb} +0 -0
- data/lib/bogus/{not_all_expectations_satisfied.rb → stubbing/not_all_expectations_satisfied.rb} +0 -0
- data/lib/bogus/{overwrites_methods.rb → stubbing/overwrites_methods.rb} +0 -0
- data/lib/bogus/{record_interactions.rb → stubbing/record_interactions.rb} +0 -0
- data/lib/bogus/{resets_stubbed_methods.rb → stubbing/resets_stubbed_methods.rb} +0 -0
- data/lib/bogus/{same_class.rb → stubbing/same_class.rb} +0 -0
- data/lib/bogus/{shadow.rb → stubbing/shadow.rb} +0 -0
- data/lib/bogus/{tracks_existence_of_test_doubles.rb → stubbing/tracks_existence_of_test_doubles.rb} +0 -0
- data/lib/bogus/{undefined_return_value.rb → stubbing/undefined_return_value.rb} +4 -0
- data/lib/bogus/{verifies_stub_definition.rb → stubbing/verifies_stub_definition.rb} +0 -0
- data/lib/bogus/version.rb +1 -1
- data/license.md +9 -0
- data/spec/bogus/contracts/adds_contract_verification_spec.rb +154 -0
- data/spec/bogus/contracts/adds_recording_spec.rb +43 -0
- data/spec/bogus/{interactions_repository_spec.rb → contracts/interactions_repository_spec.rb} +0 -0
- data/spec/bogus/{proxy_class_spec.rb → contracts/proxy_class_spec.rb} +0 -0
- data/spec/bogus/{records_double_interactions_spec.rb → contracts/records_double_interactions_spec.rb} +0 -0
- data/spec/bogus/{verifies_contracts_spec.rb → contracts/verifies_contracts_spec.rb} +0 -0
- data/spec/bogus/fakes/base_class_identifier_spec.rb +67 -0
- data/spec/bogus/{class_methods_spec.rb → fakes/class_methods_spec.rb} +0 -0
- data/spec/bogus/{converts_name_to_class_spec.rb → fakes/converts_name_to_class_spec.rb} +1 -1
- data/spec/bogus/{copies_classes_spec.rb → fakes/copies_classes_spec.rb} +3 -7
- data/spec/bogus/{creates_fakes_spec.rb → fakes/creates_fakes_spec.rb} +1 -1
- data/spec/bogus/{creates_fakes_with_stubbed_methods_spec.rb → fakes/creates_fakes_with_stubbed_methods_spec.rb} +0 -0
- data/spec/bogus/{fake_ar_attributes_spec.rb → fakes/fake_ar_attributes_spec.rb} +0 -0
- data/spec/bogus/{fake_configuration_spec.rb → fakes/fake_configuration_spec.rb} +0 -0
- data/spec/bogus/{fake_registry_spec.rb → fakes/fake_registry_spec.rb} +0 -0
- data/spec/bogus/fakes/fake_spec.rb +8 -0
- data/spec/bogus/{fakes_classes_spec.rb → fakes/fakes_classes_spec.rb} +0 -0
- data/spec/bogus/{faking_factories_spec.rb → fakes/faking_factories_spec.rb} +0 -0
- data/spec/bogus/{frozen_fakes_spec.rb → fakes/frozen_fakes_spec.rb} +0 -0
- data/spec/bogus/{instance_methods_spec.rb → fakes/instance_methods_spec.rb} +0 -0
- data/spec/bogus/{makes_ducks_spec.rb → fakes/makes_ducks_spec.rb} +0 -0
- data/spec/bogus/{makes_substitute_methods_spec.rb → fakes/makes_substitute_methods_spec.rb} +0 -0
- data/spec/bogus/{method_copiers_spec.rb → fakes/method_copiers_spec.rb} +0 -0
- data/spec/bogus/{overwriten_classes_spec.rb → fakes/overwriten_classes_spec.rb} +0 -0
- data/spec/bogus/{overwrites_classes_spec.rb → fakes/overwrites_classes_spec.rb} +0 -0
- data/spec/bogus/{registers_created_fakes_spec.rb → fakes/registers_created_fakes_spec.rb} +0 -0
- data/spec/bogus/{resets_overwritten_classes_spec.rb → fakes/resets_overwritten_classes_spec.rb} +0 -0
- data/spec/bogus/mocking_dsl_spec.rb +2 -2
- data/spec/bogus/{anything_spec.rb → stubbing/anything_spec.rb} +0 -0
- data/spec/bogus/{double_spec.rb → stubbing/double_spec.rb} +0 -0
- data/spec/bogus/{ensures_all_interactions_satisfied_spec.rb → stubbing/ensures_all_interactions_satisfied_spec.rb} +0 -0
- data/spec/bogus/{have_received_matcher_spec.rb → stubbing/have_received_matcher_spec.rb} +0 -0
- data/spec/bogus/{interaction_spec.rb → stubbing/interaction_spec.rb} +0 -0
- data/spec/bogus/{multi_stubber_spec.rb → stubbing/multi_stubber_spec.rb} +0 -0
- data/spec/bogus/{overwrites_methods_spec.rb → stubbing/overwrites_methods_spec.rb} +0 -0
- data/spec/bogus/{record_interactions_spec.rb → stubbing/record_interactions_spec.rb} +0 -0
- data/spec/bogus/{resets_stubbed_methods_spec.rb → stubbing/resets_stubbed_methods_spec.rb} +0 -0
- data/spec/bogus/{shadow_spec.rb → stubbing/shadow_spec.rb} +0 -0
- data/spec/bogus/{tracks_existence_of_test_doubles_spec.rb → stubbing/tracks_existence_of_test_doubles_spec.rb} +0 -0
- data/spec/bogus/stubbing/undefined_return_value_spec.rb +18 -0
- data/spec/bogus/{verifies_stub_definition_spec.rb → stubbing/verifies_stub_definition_spec.rb} +0 -0
- metadata +176 -160
- data/features/minitest/minitest_support.feature +0 -119
- data/lib/bogus/rspec_extensions.rb +0 -31
- data/spec/bogus/adds_recording_spec.rb +0 -77
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
bogus (0.1.
|
4
|
+
bogus (0.1.4)
|
5
5
|
dependor (>= 0.0.4)
|
6
6
|
|
7
7
|
GEM
|
@@ -22,14 +22,14 @@ GEM
|
|
22
22
|
multi_json (~> 1.0)
|
23
23
|
archive-tar-minitar (0.5.2)
|
24
24
|
arel (3.0.2)
|
25
|
-
aruba (0.
|
26
|
-
childprocess (>= 0.
|
25
|
+
aruba (0.5.3)
|
26
|
+
childprocess (>= 0.3.6)
|
27
27
|
cucumber (>= 1.1.1)
|
28
|
-
|
29
|
-
rspec (>= 2.7.0)
|
28
|
+
rspec-expectations (>= 2.7.0)
|
30
29
|
builder (3.0.4)
|
31
|
-
childprocess (0.3.
|
32
|
-
ffi (~> 1.0.
|
30
|
+
childprocess (0.3.9)
|
31
|
+
ffi (~> 1.0, >= 1.0.11)
|
32
|
+
coderay (1.0.9)
|
33
33
|
colorize (0.5.8)
|
34
34
|
coveralls (0.6.7)
|
35
35
|
colorize
|
@@ -37,62 +37,78 @@ GEM
|
|
37
37
|
rest-client
|
38
38
|
simplecov (>= 0.7)
|
39
39
|
thor
|
40
|
-
cucumber (1.3.
|
40
|
+
cucumber (1.3.5)
|
41
41
|
builder (>= 2.1.2)
|
42
42
|
diff-lcs (>= 1.1.3)
|
43
43
|
gherkin (~> 2.12.0)
|
44
44
|
multi_json (~> 1.7.5)
|
45
|
-
multi_test (
|
46
|
-
dependor (0.0.
|
45
|
+
multi_test (>= 0.0.2)
|
46
|
+
dependor (0.0.6)
|
47
47
|
diff-lcs (1.2.4)
|
48
|
-
ffi (1.0
|
49
|
-
ffi (1.0
|
48
|
+
ffi (1.9.0)
|
49
|
+
ffi (1.9.0-java)
|
50
|
+
formatador (0.2.4)
|
50
51
|
gherkin (2.12.0)
|
51
52
|
multi_json (~> 1.3)
|
52
53
|
gherkin (2.12.0-java)
|
53
54
|
multi_json (~> 1.3)
|
54
55
|
growl (1.0.3)
|
55
|
-
guard (1.
|
56
|
-
|
56
|
+
guard (1.8.1)
|
57
|
+
formatador (>= 0.2.4)
|
58
|
+
listen (>= 1.0.0)
|
59
|
+
lumberjack (>= 1.0.2)
|
60
|
+
pry (>= 0.9.10)
|
57
61
|
thor (>= 0.14.6)
|
58
62
|
guard-ctags-bundler (0.1.6)
|
59
63
|
guard (>= 1.1)
|
60
|
-
guard-cucumber (1.
|
64
|
+
guard-cucumber (1.4.0)
|
61
65
|
cucumber (>= 1.2.0)
|
62
66
|
guard (>= 1.1.0)
|
63
|
-
guard-rspec (
|
64
|
-
guard (>= 1.
|
67
|
+
guard-rspec (3.0.2)
|
68
|
+
guard (>= 1.8)
|
69
|
+
rspec (~> 2.13)
|
65
70
|
i18n (0.6.1)
|
66
71
|
json (1.8.0)
|
67
72
|
json (1.8.0-java)
|
68
|
-
libnotify (0.
|
69
|
-
ffi (
|
70
|
-
listen (
|
71
|
-
rb-
|
72
|
-
rb-
|
73
|
-
rb-
|
74
|
-
|
73
|
+
libnotify (0.8.1)
|
74
|
+
ffi (>= 1.0.11)
|
75
|
+
listen (1.2.2)
|
76
|
+
rb-fsevent (>= 0.9.3)
|
77
|
+
rb-inotify (>= 0.9)
|
78
|
+
rb-kqueue (>= 0.2)
|
79
|
+
lumberjack (1.0.4)
|
80
|
+
method_source (0.8.1)
|
81
|
+
mime-types (1.23)
|
75
82
|
minitest (5.0.6)
|
76
83
|
multi_json (1.7.7)
|
77
|
-
multi_test (0.0.
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
84
|
+
multi_test (0.0.2)
|
85
|
+
pry (0.9.12.2)
|
86
|
+
coderay (~> 1.0.5)
|
87
|
+
method_source (~> 0.8)
|
88
|
+
slop (~> 3.4)
|
89
|
+
pry (0.9.12.2-java)
|
90
|
+
coderay (~> 1.0.5)
|
91
|
+
method_source (~> 0.8)
|
92
|
+
slop (~> 3.4)
|
93
|
+
spoon (~> 0.0)
|
94
|
+
rake (10.1.0)
|
95
|
+
rb-fsevent (0.9.3)
|
96
|
+
rb-inotify (0.9.0)
|
97
|
+
ffi (>= 0.5.0)
|
98
|
+
rb-kqueue (0.2.0)
|
83
99
|
ffi (>= 0.5.0)
|
84
|
-
relish (0.
|
100
|
+
relish (0.7)
|
85
101
|
archive-tar-minitar (>= 0.5.2)
|
86
102
|
json (>= 1.4.6)
|
87
103
|
rest-client (>= 1.6.1)
|
88
104
|
rest-client (1.6.7)
|
89
105
|
mime-types (>= 1.16)
|
90
106
|
rr (1.1.1)
|
91
|
-
rspec (2.14.
|
107
|
+
rspec (2.14.1)
|
92
108
|
rspec-core (~> 2.14.0)
|
93
109
|
rspec-expectations (~> 2.14.0)
|
94
110
|
rspec-mocks (~> 2.14.0)
|
95
|
-
rspec-core (2.14.
|
111
|
+
rspec-core (2.14.4)
|
96
112
|
rspec-expectations (2.14.0)
|
97
113
|
diff-lcs (>= 1.1.3, < 2.0)
|
98
114
|
rspec-mocks (2.14.1)
|
@@ -100,7 +116,10 @@ GEM
|
|
100
116
|
multi_json (~> 1.0)
|
101
117
|
simplecov-html (~> 0.7.1)
|
102
118
|
simplecov-html (0.7.1)
|
103
|
-
|
119
|
+
slop (3.4.5)
|
120
|
+
spoon (0.0.4)
|
121
|
+
ffi
|
122
|
+
thor (0.18.1)
|
104
123
|
tzinfo (0.3.37)
|
105
124
|
|
106
125
|
PLATFORMS
|
data/Guardfile
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# A sample Guardfile
|
2
2
|
# More info at https://github.com/guard/guard#readme
|
3
3
|
|
4
|
-
|
4
|
+
interactor :off
|
5
|
+
|
6
|
+
guard 'rspec' do
|
5
7
|
watch(%r{^spec/.+_spec\.rb$})
|
6
8
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
7
9
|
watch('spec/spec_helper.rb') { "spec" }
|
data/Guardfile.cucumber
CHANGED
data/README.md
CHANGED
@@ -54,7 +54,7 @@ end
|
|
54
54
|
|
55
55
|
## License
|
56
56
|
|
57
|
-
MIT. See the LICENSE file.
|
57
|
+
MIT. See the [LICENSE file][license].
|
58
58
|
|
59
59
|
## Authors
|
60
60
|
|
@@ -70,3 +70,4 @@ MIT. See the LICENSE file.
|
|
70
70
|
[ar-support]: https://www.relishapp.com/bogus/bogus/docs/configuration/fake-ar-attributes
|
71
71
|
[global-configuration]: https://www.relishapp.com/bogus/bogus/docs/fakes/global-fake-configuration
|
72
72
|
[contract-tests]: https://www.relishapp.com/bogus/bogus/docs/contract-tests
|
73
|
+
[license]: features/license.md
|
data/bogus.gemspec
CHANGED
@@ -7,6 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = Bogus::VERSION
|
8
8
|
s.authors = ["Adam Pohorecki"]
|
9
9
|
s.email = ["adam@pohorecki.pl"]
|
10
|
+
s.license = 'MIT'
|
10
11
|
s.homepage = "https://github.com/psyho/bogus"
|
11
12
|
s.summary = %q{Create fakes to make your isolated unit tests reliable.}
|
12
13
|
s.description = %q{Decreases the need to write integration tests by ensuring that the things you stub or mock actually exist.}
|
data/features/.nav
CHANGED
@@ -17,9 +17,11 @@
|
|
17
17
|
- contract_tests_stubs.feature
|
18
18
|
- contract_tests_spies.feature
|
19
19
|
- return_value_contracts.feature
|
20
|
+
- custom_overwritten_class.feature
|
20
21
|
- configuration (Configuration Options):
|
21
22
|
- search_modules.feature
|
22
23
|
- fake_ar_attributes.feature
|
24
|
+
- minitest_support.feature
|
23
25
|
- changelog.md
|
24
26
|
- license.md
|
25
27
|
- authors.md
|
data/features/changelog.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 0.1.4
|
2
|
+
|
3
|
+
- Support for contracts in minitest
|
4
|
+
- Allowed customizing the class being overwritten by verify_contract
|
5
|
+
- Fixed is_a? behavior for fakes
|
6
|
+
- Fake#is_a? now returns true for superclasses of and modules included into the faked class.
|
7
|
+
- Reorganized the code into subdirectories
|
8
|
+
|
1
9
|
## 0.1.3
|
2
10
|
|
3
11
|
- Support for minitest
|
@@ -0,0 +1,115 @@
|
|
1
|
+
Feature: Customizing the overwritten class
|
2
|
+
|
3
|
+
Typically, when you specify a contract to be verified, you do it like this:
|
4
|
+
|
5
|
+
describe SomeClass do
|
6
|
+
verify_contract(:some_fake_name)
|
7
|
+
end
|
8
|
+
|
9
|
+
When you do this, under the hood Bogus replaces `SomeClass` with a proxy that records any calls made to the class and its instances for the duration of the test.
|
10
|
+
|
11
|
+
If the class you want to be overwritten is not the one that is described, you can customize it like so:
|
12
|
+
|
13
|
+
describe "not a class" do
|
14
|
+
verify_contract(:some_fake_name) { SomeClass }
|
15
|
+
end
|
16
|
+
|
17
|
+
In case there is no described class and you don't provide a custom one to be overwritten, the class will be guessed based on the name of the fake:
|
18
|
+
|
19
|
+
describe "not a class" do
|
20
|
+
verify_contract(:some_fake_name)
|
21
|
+
end
|
22
|
+
|
23
|
+
In the above example, Bogus will try to overwrite a class named `SomeFakeName`.
|
24
|
+
|
25
|
+
Background:
|
26
|
+
Given a file named "library.rb" with:
|
27
|
+
"""ruby
|
28
|
+
class PublicLibrary
|
29
|
+
def initialize
|
30
|
+
@books = []
|
31
|
+
end
|
32
|
+
|
33
|
+
def has_book?(book)
|
34
|
+
@books.include?(book)
|
35
|
+
end
|
36
|
+
|
37
|
+
def checkout(book)
|
38
|
+
@books.delete(book)
|
39
|
+
end
|
40
|
+
|
41
|
+
def return(book)
|
42
|
+
@books << book
|
43
|
+
end
|
44
|
+
end
|
45
|
+
"""
|
46
|
+
|
47
|
+
Given a file named "student.rb" with:
|
48
|
+
"""ruby
|
49
|
+
class Student
|
50
|
+
def read(book, library = PublicLibrary.new)
|
51
|
+
if library.has_book?(book)
|
52
|
+
library.checkout(book)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
"""
|
57
|
+
|
58
|
+
And a spec file named "student_spec.rb" with:
|
59
|
+
"""ruby
|
60
|
+
require_relative 'student'
|
61
|
+
require_relative 'library'
|
62
|
+
|
63
|
+
describe Student do
|
64
|
+
fake(:library) { PublicLibrary }
|
65
|
+
|
66
|
+
it "checks out the book from library if it is available" do
|
67
|
+
student = Student.new
|
68
|
+
mock(library).has_book?("Moby Dick") { true }
|
69
|
+
mock(library).checkout("Moby Dick") { "Moby Dick" }
|
70
|
+
|
71
|
+
student.read("Moby Dick", library)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "does not check out the book from library if not available" do
|
75
|
+
student = Student.new
|
76
|
+
mock(library).has_book?("Moby Dick") { false }
|
77
|
+
|
78
|
+
student.read("Moby Dick", library)
|
79
|
+
|
80
|
+
library.should_not have_received.checkout("Moby Dick")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
"""
|
84
|
+
|
85
|
+
Scenario: Verifying contract for a class that is not the described_class
|
86
|
+
Then spec file with following content should pass:
|
87
|
+
"""ruby
|
88
|
+
require_relative 'library'
|
89
|
+
|
90
|
+
describe "Borrowing books from library" do
|
91
|
+
verify_contract(:library) { PublicLibrary }
|
92
|
+
|
93
|
+
let(:library) { PublicLibrary.new }
|
94
|
+
|
95
|
+
it "allows checking out books that are in the inventory" do
|
96
|
+
library.return("Moby Dick")
|
97
|
+
|
98
|
+
library.has_book?("Moby Dick").should be_true
|
99
|
+
end
|
100
|
+
|
101
|
+
it "does not allow checking out unavailable books" do
|
102
|
+
library.has_book?("Moby Dick").should be_false
|
103
|
+
end
|
104
|
+
|
105
|
+
it "marks books as unavailable after they are checked out" do
|
106
|
+
library.return("Moby Dick")
|
107
|
+
|
108
|
+
library.checkout("Moby Dick")
|
109
|
+
|
110
|
+
library.has_book?("Moby Dick").should be_false
|
111
|
+
end
|
112
|
+
end
|
113
|
+
"""
|
114
|
+
|
115
|
+
|
@@ -0,0 +1,228 @@
|
|
1
|
+
Feature: minitest support
|
2
|
+
|
3
|
+
minitest is supported by Bogus both with the classic assert-style syntax and the minitest/spec expectation syntax.
|
4
|
+
|
5
|
+
Background:
|
6
|
+
Given a file named "library.rb" with:
|
7
|
+
"""ruby
|
8
|
+
class Library
|
9
|
+
def self.books
|
10
|
+
end
|
11
|
+
|
12
|
+
def checkout(book)
|
13
|
+
end
|
14
|
+
|
15
|
+
def return_book(book)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
"""
|
19
|
+
|
20
|
+
Given a file named "book_index.rb" with:
|
21
|
+
"""ruby
|
22
|
+
class BookIndex
|
23
|
+
def self.by_author(author)
|
24
|
+
Library.books.select{|book| book[:author] == author}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
"""
|
28
|
+
|
29
|
+
Given a file named "student.rb" with:
|
30
|
+
"""ruby
|
31
|
+
class Student
|
32
|
+
def initialize(library)
|
33
|
+
@library = library
|
34
|
+
end
|
35
|
+
|
36
|
+
def study(*book_titles)
|
37
|
+
book_titles.each do |book_title|
|
38
|
+
@library.checkout(book_title)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
"""
|
43
|
+
|
44
|
+
Scenario: Auto-verification of unsatisfied mocks
|
45
|
+
Then minitest file "student_test.rb" with the following content should fail:
|
46
|
+
"""ruby
|
47
|
+
require 'minitest/autorun'
|
48
|
+
require 'bogus/minitest'
|
49
|
+
|
50
|
+
require_relative 'student'
|
51
|
+
require_relative 'library'
|
52
|
+
|
53
|
+
class StudentTest < MiniTest::Unit::TestCase
|
54
|
+
def test_library_checkouts
|
55
|
+
library = fake(:library)
|
56
|
+
student = Student.new(library)
|
57
|
+
mock(library).checkout("Moby Dick")
|
58
|
+
mock(library).checkout("Sherlock Holmes")
|
59
|
+
|
60
|
+
student.study("Moby Dick")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
"""
|
64
|
+
|
65
|
+
Scenario: Spying on method calls with assert syntax
|
66
|
+
Then minitest file "student_test.rb" with the following content should pass:
|
67
|
+
"""ruby
|
68
|
+
require 'minitest/autorun'
|
69
|
+
require 'bogus/minitest'
|
70
|
+
|
71
|
+
require_relative 'student'
|
72
|
+
require_relative 'library'
|
73
|
+
|
74
|
+
class StudentTest < MiniTest::Unit::TestCase
|
75
|
+
def setup
|
76
|
+
@library = fake(:library)
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_library_checkouts
|
80
|
+
student = Student.new(@library)
|
81
|
+
|
82
|
+
student.study("Moby Dick", "Sherlock Holmes")
|
83
|
+
|
84
|
+
assert_received @library, :checkout, ["Moby Dick"]
|
85
|
+
assert_received @library, :checkout, ["Sherlock Holmes"], "optional message"
|
86
|
+
refute_received @library, :return_book, ["Moby Dick"]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
"""
|
90
|
+
|
91
|
+
Scenario: Spying on method calls with expectation syntax
|
92
|
+
Then minitest file "student_spec.rb" with the following content should pass:
|
93
|
+
"""ruby
|
94
|
+
require 'minitest/autorun'
|
95
|
+
require 'bogus/minitest/spec'
|
96
|
+
|
97
|
+
require_relative 'student'
|
98
|
+
require_relative 'library'
|
99
|
+
|
100
|
+
describe Student do
|
101
|
+
describe "#study" do
|
102
|
+
fake(:library)
|
103
|
+
|
104
|
+
it "studies using books from library" do
|
105
|
+
student = Student.new(library)
|
106
|
+
|
107
|
+
student.study("Moby Dick", "Sherlock Holmes")
|
108
|
+
|
109
|
+
library.must_have_received :checkout, ["Moby Dick"]
|
110
|
+
library.must_have_received :checkout, ["Sherlock Holmes"]
|
111
|
+
library.wont_have_received :return_book, ["Moby Dick"]
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
"""
|
116
|
+
|
117
|
+
Scenario: Describe-level class faking
|
118
|
+
Then minitest file "book_index_spec.rb" with the following content should pass:
|
119
|
+
"""ruby
|
120
|
+
require 'minitest/autorun'
|
121
|
+
require 'bogus/minitest/spec'
|
122
|
+
|
123
|
+
require_relative 'book_index'
|
124
|
+
require_relative 'library'
|
125
|
+
|
126
|
+
describe BookIndex do
|
127
|
+
fake_class(Library, books: [])
|
128
|
+
|
129
|
+
it "returns books written by author" do
|
130
|
+
BookIndex.by_author("Mark Twain").must_equal []
|
131
|
+
end
|
132
|
+
end
|
133
|
+
"""
|
134
|
+
|
135
|
+
Scenario: Negative contract verification
|
136
|
+
Then minitest file "student_and_library_spec.rb" with the following content should fail:
|
137
|
+
"""ruby
|
138
|
+
require 'minitest/autorun'
|
139
|
+
require 'bogus/minitest/spec'
|
140
|
+
|
141
|
+
require_relative 'student'
|
142
|
+
require_relative 'library'
|
143
|
+
|
144
|
+
describe Student do
|
145
|
+
describe "#study" do
|
146
|
+
fake(:library)
|
147
|
+
|
148
|
+
it "studies using books from library" do
|
149
|
+
Student.new(library).study("Moby Dick")
|
150
|
+
library.must_have_received :checkout, ["Moby Dick"]
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe Library do
|
156
|
+
verify_contract(:library)
|
157
|
+
end
|
158
|
+
"""
|
159
|
+
|
160
|
+
Scenario: Positive contract verification
|
161
|
+
Then minitest file "student_and_library_spec.rb" with the following content should pass:
|
162
|
+
"""ruby
|
163
|
+
require 'minitest/autorun'
|
164
|
+
require 'bogus/minitest/spec'
|
165
|
+
|
166
|
+
require_relative 'student'
|
167
|
+
require_relative 'library'
|
168
|
+
|
169
|
+
describe Student do
|
170
|
+
describe "#study" do
|
171
|
+
fake(:library)
|
172
|
+
|
173
|
+
it "studies using books from library" do
|
174
|
+
Student.new(library).study("Moby Dick")
|
175
|
+
library.must_have_received :checkout, ["Moby Dick"]
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe Library do
|
181
|
+
verify_contract(:library)
|
182
|
+
|
183
|
+
describe '#checkout' do
|
184
|
+
it "checks books out" do
|
185
|
+
Library.new.checkout("Moby Dick")
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
"""
|
190
|
+
|
191
|
+
Scenario: Custom verified class
|
192
|
+
Then minitest file "student_and_library_spec.rb" with the following content should pass:
|
193
|
+
"""ruby
|
194
|
+
require 'minitest/autorun'
|
195
|
+
require 'bogus/minitest/spec'
|
196
|
+
|
197
|
+
class NetworkLogger
|
198
|
+
def info(msg)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
class OrderProcessor
|
203
|
+
def process(order, logger = NetworkLogger.new)
|
204
|
+
logger.info("#{order} processed")
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
describe OrderProcessor do
|
209
|
+
describe "#process" do
|
210
|
+
fake(:logger) { NetworkLogger }
|
211
|
+
|
212
|
+
it "processes orders" do
|
213
|
+
OrderProcessor.new.process("burger & fries", logger)
|
214
|
+
logger.must_have_received :info, ["burger & fries processed"]
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
describe "Using network logger" do
|
220
|
+
verify_contract(:logger) { NetworkLogger }
|
221
|
+
|
222
|
+
describe '#info' do
|
223
|
+
it "logs on info level" do
|
224
|
+
NetworkLogger.new.info("burger & fries processed")
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
"""
|