bogus 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/.travis.yml +1 -0
  2. data/Gemfile.lock +6 -1
  3. data/README.md +3 -0
  4. data/features/changelog.md +30 -22
  5. data/features/configuration/fake_ar_attributes.feature +3 -1
  6. data/features/configuration/search_modules.feature +5 -0
  7. data/features/contract_tests/contract_tests_mocks.feature +12 -1
  8. data/features/contract_tests/contract_tests_spies.feature +14 -2
  9. data/features/contract_tests/contract_tests_stubs.feature +13 -2
  10. data/features/contract_tests/return_value_contracts.feature +15 -4
  11. data/features/fakes/anonymous_doubles.feature +15 -1
  12. data/features/fakes/duck_types.feature +12 -2
  13. data/features/fakes/fake_objects.feature +11 -1
  14. data/features/fakes/global_fake_configuration.feature +4 -1
  15. data/features/readme.md +2 -2
  16. data/features/safe_stubbing/argument_matchers.feature +32 -2
  17. data/features/safe_stubbing/safe_mocking.feature +9 -2
  18. data/features/safe_stubbing/safe_stubbing.feature +11 -2
  19. data/features/safe_stubbing/spies.feature +52 -1
  20. data/features/step_definitions/rspec_steps.rb +1 -2
  21. data/features/support/env.rb +19 -0
  22. data/lib/bogus/active_record_accessors.rb +4 -4
  23. data/lib/bogus/adds_recording.rb +1 -0
  24. data/lib/bogus/any_args.rb +32 -3
  25. data/lib/bogus/class_methods.rb +7 -1
  26. data/lib/bogus/copies_classes.rb +5 -2
  27. data/lib/bogus/fake.rb +0 -2
  28. data/lib/bogus/have_received_matcher.rb +5 -0
  29. data/lib/bogus/interaction.rb +66 -35
  30. data/lib/bogus/interactions_repository.rb +1 -1
  31. data/lib/bogus/makes_substitute_methods.rb +3 -2
  32. data/lib/bogus/mocking_dsl.rb +8 -0
  33. data/lib/bogus/public_methods.rb +1 -1
  34. data/lib/bogus/rspec_extensions.rb +8 -1
  35. data/lib/bogus/same_class.rb +14 -0
  36. data/lib/bogus/shadow.rb +8 -12
  37. data/lib/bogus/verifies_stub_definition.rb +1 -5
  38. data/lib/bogus/version.rb +1 -1
  39. data/spec/bogus/adds_recording_spec.rb +8 -0
  40. data/spec/bogus/class_methods_spec.rb +8 -2
  41. data/spec/bogus/clean_ruby_spec.rb +15 -0
  42. data/spec/bogus/have_received_matcher_spec.rb +45 -27
  43. data/spec/bogus/instance_methods_spec.rb +1 -1
  44. data/spec/bogus/interaction_spec.rb +87 -83
  45. data/spec/bogus/interactions_repository_spec.rb +8 -11
  46. data/spec/bogus/shadow_spec.rb +4 -1
  47. metadata +81 -39
  48. checksums.yaml +0 -7
@@ -3,4 +3,5 @@ rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
5
  - 2.0
6
+ - jruby-19mode
6
7
  script: bundle exec rspec spec && bundle exec cucumber --tag ~@wip
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bogus (0.1.0)
4
+ bogus (0.1.1)
5
5
  dependor (>= 0.0.4)
6
6
 
7
7
  GEM
@@ -45,8 +45,11 @@ GEM
45
45
  dependor (0.0.5)
46
46
  diff-lcs (1.1.3)
47
47
  ffi (1.0.11)
48
+ ffi (1.0.11-java)
48
49
  gherkin (2.11.0)
49
50
  json (>= 1.4.6)
51
+ gherkin (2.11.0-java)
52
+ json (>= 1.4.6)
50
53
  growl (1.0.3)
51
54
  guard (1.1.1)
52
55
  listen (>= 0.4.2)
@@ -60,6 +63,7 @@ GEM
60
63
  guard (>= 1.1)
61
64
  i18n (0.6.1)
62
65
  json (1.7.3)
66
+ json (1.7.3-java)
63
67
  libnotify (0.7.4)
64
68
  ffi (~> 1.0.11)
65
69
  listen (0.4.5)
@@ -97,6 +101,7 @@ GEM
97
101
  tzinfo (0.3.37)
98
102
 
99
103
  PLATFORMS
104
+ java
100
105
  ruby
101
106
 
102
107
  DEPENDENCIES
data/README.md CHANGED
@@ -7,6 +7,7 @@ Bogus aims to make your unit tests more reliable by ensuring that you don't stub
7
7
  [![Coverage Status](https://coveralls.io/repos/psyho/bogus/badge.png?branch=master)](https://coveralls.io/r/psyho/bogus?branch=master)
8
8
  [![Gem Version](https://badge.fury.io/rb/bogus.png)](http://badge.fury.io/rb/bogus)
9
9
  [![Dependency Status](https://gemnasium.com/psyho/bogus.png)](https://gemnasium.com/psyho/bogus)
10
+ [![githalytics.com alpha](https://cruel-carlota.pagodabox.com/9908a24d18bc26923a8ab08c28fcc8e5 "githalytics.com")](http://githalytics.com/psyho/bogus)
10
11
 
11
12
  ## Example
12
13
 
@@ -24,6 +25,8 @@ class PostAdder < Struct.new(:post_repository)
24
25
  end
25
26
  end
26
27
 
28
+ require 'bogus/rspec'
29
+
27
30
  describe PostAdder do
28
31
  fake(:post_repository)
29
32
 
@@ -1,18 +1,26 @@
1
- ## 0.0.1
1
+ ## 0.1.1
2
2
 
3
- Initial version.
3
+ - Minor bugfixes to Ruby 2.0 support
4
+ - Support for Rubinius (head) and JRuby
5
+ - Overwrite described_class in on verify_contract
6
+ - Added with{} and any(Klass) argument matchers
7
+ - Added have_received(:name, args) syntax
4
8
 
5
- - Fakes.
6
- - Safe spying, stubbing, mocking.
7
- - Veryfying contracts defined by test doubles.
9
+ ## 0.1.0
8
10
 
9
- ## 0.0.2
11
+ - Support for stubbing on frozen fakes
12
+ - Safe stubbing of constructors
13
+ - Fixed spying on anonymous fakes
14
+ - Automatic handling of ActiveRecord columns
15
+ - Support Ruby 2.0 keyword arguments
10
16
 
11
- - Makes it possible to stub method calls on objects that utilize method missing.
12
- - Removed the need to require both bogus and bogus/rspec.
13
- - Implemented anonymous fakes.
14
- - Fixed a bug in copying ActiveRecord classes.
15
- - (internal) Replaced autoloads with require.
17
+ ### Breaking changes:
18
+
19
+ - Fakes no longer return themselves from unstubbed method calls, because this was often a source of confusion. In the new version we return a Bogus::UndefinedReturnValue which contains the method name and arguments from where it was returned.
20
+
21
+ ## 0.0.4
22
+
23
+ - Support mocking methods with optional parameters
16
24
 
17
25
  ## 0.0.3
18
26
 
@@ -23,18 +31,18 @@ Initial version.
23
31
  - Replacing classes with fakes
24
32
  - Extracting common interface out of multpile classes to create duck types
25
33
 
26
- ## 0.0.4
27
-
28
- - Support mocking methods with optional parameters
34
+ ## 0.0.2
29
35
 
30
- ## 0.1.0 (in progress)
36
+ - Makes it possible to stub method calls on objects that utilize method missing.
37
+ - Removed the need to require both bogus and bogus/rspec.
38
+ - Implemented anonymous fakes.
39
+ - Fixed a bug in copying ActiveRecord classes.
40
+ - (internal) Replaced autoloads with require.
31
41
 
32
- - Support for stubbing on frozen fakes
33
- - Safe stubbing of constructors
34
- - Fixed spying on anonymous fakes
35
- - Automatic handling of ActiveRecord columns
36
- - Support Ruby 2.0 keyword arguments
42
+ ## 0.0.1
37
43
 
38
- ### Breaking changes:
44
+ Initial version.
39
45
 
40
- - Fakes no longer return themselves from unstubbed method calls, because this was often a source of confusion. In the new version we return a Bogus::UndefinedReturnValue which contains the method name and arguments from where it was returned.
46
+ - Fakes.
47
+ - Safe spying, stubbing, mocking.
48
+ - Veryfying contracts defined by test doubles.
@@ -18,7 +18,7 @@ Feature: fake_ar_attributes
18
18
  end
19
19
 
20
20
  Scenario: Adding missing accessors to AR classes
21
- Given a file named "foo.rb" with:
21
+ Given a file named "blog_post.rb" with:
22
22
  """ruby
23
23
  require 'active_record'
24
24
  require 'nulldb'
@@ -43,6 +43,8 @@ Feature: fake_ar_attributes
43
43
 
44
44
  Then the following test should pass:
45
45
  """ruby
46
+ require_relative 'blog_post'
47
+
46
48
  post = fake(:blog_post, name: "the name")
47
49
  stub(post).tags { "foo, bar" }
48
50
 
@@ -9,7 +9,10 @@ Feature: search_modules
9
9
  def foo
10
10
  end
11
11
  end
12
+ """
12
13
 
14
+ Given a file named "baz.rb" with:
15
+ """ruby
13
16
  module Bar
14
17
  class Baz
15
18
  def baz
@@ -20,6 +23,8 @@ Feature: search_modules
20
23
 
21
24
  Then spec file with following content should pass:
22
25
  """ruby
26
+ require_relative 'foo'
27
+ require_relative 'baz'
23
28
 
24
29
  Bogus.configure do |c|
25
30
  c.search_modules << Bar
@@ -3,7 +3,7 @@ Feature: Contract tests with mocks
3
3
  Whenever you mock something, you specify a contract on the arguments/return value pair. Bogus can check automatically Whether this contract was satisfied.
4
4
 
5
5
  Background:
6
- Given a file named "foo.rb" with:
6
+ Given a file named "library.rb" with:
7
7
  """ruby
8
8
  class Library
9
9
  def initialize
@@ -22,7 +22,10 @@ Feature: Contract tests with mocks
22
22
  @books << book
23
23
  end
24
24
  end
25
+ """
25
26
 
27
+ Given a file named "student.rb" with:
28
+ """ruby
26
29
  class Student
27
30
  def read(book, library = Library.new)
28
31
  if library.has_book?(book)
@@ -31,8 +34,12 @@ Feature: Contract tests with mocks
31
34
  end
32
35
  end
33
36
  """
37
+
34
38
  And a spec file named "student_spec.rb" with:
35
39
  """ruby
40
+ require_relative 'student'
41
+ require_relative 'library'
42
+
36
43
  describe Student do
37
44
  fake(:library)
38
45
 
@@ -58,6 +65,8 @@ Feature: Contract tests with mocks
58
65
  Scenario: Fails when mocked methods are not called on real object
59
66
  Then spec file with following content should fail:
60
67
  """ruby
68
+ require_relative 'library'
69
+
61
70
  describe Library do
62
71
  verify_contract(:library)
63
72
 
@@ -76,6 +85,8 @@ Feature: Contract tests with mocks
76
85
  Scenario: Verifies that mocked methods are called
77
86
  Then spec file with following content should pass:
78
87
  """ruby
88
+ require_relative 'library'
89
+
79
90
  describe Library do
80
91
  verify_contract(:library)
81
92
 
@@ -3,13 +3,16 @@ Feature: Contract tests with spies
3
3
  Whenever you spy on method invocations, it creates a contract specifying that some method can be called with a particular set of arguments. It can be automatically verified by Bogus, whether the method was actually called with those arguments.
4
4
 
5
5
  Background:
6
- Given a file named "foo.rb" with:
6
+ Given a file named "library.rb" with:
7
7
  """ruby
8
8
  class Library
9
9
  def checkout(book)
10
10
  end
11
11
  end
12
+ """
12
13
 
14
+ Given a file named "student.rb" with:
15
+ """ruby
13
16
  class Student
14
17
  def read(book, library = Library.new)
15
18
  library.checkout(book)
@@ -17,8 +20,12 @@ Feature: Contract tests with spies
17
20
  end
18
21
  end
19
22
  """
23
+
20
24
  And a spec file named "student_spec.rb" with:
21
25
  """ruby
26
+ require_relative 'student'
27
+ require_relative 'library'
28
+
22
29
  describe Student do
23
30
  fake(:library)
24
31
 
@@ -35,6 +42,8 @@ Feature: Contract tests with spies
35
42
  Scenario: Stubbing methods that exist on real object
36
43
  Then spec file with following content should pass:
37
44
  """ruby
45
+ require_relative 'library'
46
+
38
47
  describe Library do
39
48
  verify_contract(:library)
40
49
 
@@ -51,15 +60,18 @@ Feature: Contract tests with spies
51
60
  Scenario: Verifing that stubbed methods are tested
52
61
  Then spec file with following content should fail:
53
62
  """ruby
63
+ require_relative 'library'
64
+
54
65
  describe Library do
55
66
  verify_contract(:library)
56
-
57
67
  end
58
68
  """
59
69
 
60
70
  Scenario: Verifying that methods are tested with right arguments
61
71
  Then spec file with following content should fail:
62
72
  """ruby
73
+ require_relative 'library'
74
+
63
75
  describe Library do
64
76
  verify_contract(:library)
65
77
 
@@ -15,7 +15,7 @@ Feature: Contract tests with stubs
15
15
  will also create a contract on the method input parameters.
16
16
 
17
17
  Background:
18
- Given a file named "foo.rb" with:
18
+ Given a file named "library.rb" with:
19
19
  """ruby
20
20
  class Library
21
21
  def initialize
@@ -34,7 +34,10 @@ Feature: Contract tests with stubs
34
34
  @books << book
35
35
  end
36
36
  end
37
+ """
37
38
 
39
+ Given a file named "student.rb" with:
40
+ """ruby
38
41
  class Student
39
42
  def read(book, library = Library.new)
40
43
  if library.has_book?(book)
@@ -43,8 +46,12 @@ Feature: Contract tests with stubs
43
46
  end
44
47
  end
45
48
  """
49
+
46
50
  And a spec file named "student_spec.rb" with:
47
51
  """ruby
52
+ require_relative 'student'
53
+ require_relative 'library'
54
+
48
55
  describe Student do
49
56
  fake(:library)
50
57
 
@@ -71,6 +78,8 @@ Feature: Contract tests with stubs
71
78
  Scenario: Fails when stubbed methods are not called on real object
72
79
  Then spec file with following content should fail:
73
80
  """ruby
81
+ require_relative 'library'
82
+
74
83
  describe Library do
75
84
  verify_contract(:library)
76
85
 
@@ -89,10 +98,12 @@ Feature: Contract tests with stubs
89
98
  Scenario: Verifies that stubbed methods are called
90
99
  Then spec file with following content should pass:
91
100
  """ruby
101
+ require_relative 'library'
102
+
92
103
  describe Library do
93
104
  verify_contract(:library)
94
105
 
95
- let(:library) { Library.new }
106
+ let(:library) { described_class.new }
96
107
 
97
108
  it "allows checking out books that are in the inventory" do
98
109
  library.return("Moby Dick")
@@ -5,7 +5,7 @@ Feature: Return value contracts
5
5
  If it's not, the behavior of contract verification is not defined.
6
6
 
7
7
  Background:
8
- Given a file named "foo.rb" with:
8
+ Given a file named "session_controller.rb" with:
9
9
  """ruby
10
10
  class SessionController
11
11
  def initialize(authentication_service)
@@ -19,10 +19,10 @@ Feature: Return value contracts
19
19
  :render_error
20
20
  end
21
21
  end
22
+ """
22
23
 
23
- class WrongPassword < StandardError
24
- end
25
-
24
+ Given a file named "authentication_service.rb" with:
25
+ """ruby
26
26
  class AuthenticationService
27
27
  def initialize(user_db)
28
28
  @user_db = user_db
@@ -34,9 +34,16 @@ Feature: Return value contracts
34
34
  end
35
35
  end
36
36
  end
37
+
38
+ class WrongPassword < StandardError
39
+ end
37
40
  """
41
+
38
42
  And a spec file named "session_controller_spec.rb" with:
39
43
  """ruby
44
+ require_relative 'session_controller'
45
+ require_relative 'authentication_service'
46
+
40
47
  describe SessionController do
41
48
  fake(:authentication_service)
42
49
  let(:controller) { SessionController.new(authentication_service) }
@@ -58,6 +65,8 @@ Feature: Return value contracts
58
65
  Scenario: Bogus makes sure that all the return values recorded by stubbing are also present in tests of the real object
59
66
  Then spec file with following content should fail:
60
67
  """ruby
68
+ require_relative 'authentication_service'
69
+
61
70
  describe AuthenticationService do
62
71
  verify_contract(:authentication_service)
63
72
 
@@ -73,6 +82,8 @@ Feature: Return value contracts
73
82
  Scenario: Bogus does not fail the tests if all the recorded values have been also recorded on the real object
74
83
  Then spec file with following content should pass:
75
84
  """ruby
85
+ require_relative 'authentication_service'
86
+
76
87
  describe AuthenticationService do
77
88
  verify_contract(:authentication_service)
78
89
 
@@ -18,7 +18,7 @@ Feature: Anonymous test doubles
18
18
  stub(factory).make_validator{ proc{ false } }
19
19
 
20
20
  Background:
21
- Given a file named "foo.rb" with:
21
+ Given a file named "student.rb" with:
22
22
  """ruby
23
23
  class Student
24
24
  attr_reader :library_card
@@ -36,6 +36,8 @@ Feature: Anonymous test doubles
36
36
  Scenario: Stubbing any method with any parameters
37
37
  Then spec file with following content should pass:
38
38
  """ruby
39
+ require_relative 'student'
40
+
39
41
  describe Student do
40
42
  let(:library) { fake }
41
43
  let(:jake) { Student.new("Jake") }
@@ -53,6 +55,8 @@ Feature: Anonymous test doubles
53
55
  Scenario: Stubbing methods in initializer
54
56
  Then spec file with following content should pass:
55
57
  """ruby
58
+ require_relative 'student'
59
+
56
60
  describe Student do
57
61
  let(:library) { fake(register_junior: "the card") }
58
62
  let(:jake) { Student.new("Jake") }
@@ -77,6 +81,8 @@ Feature: Anonymous test doubles
77
81
  Scenario: Mocking any method with any parameters
78
82
  Then spec file with following content should pass:
79
83
  """ruby
84
+ require_relative 'student'
85
+
80
86
  describe Student do
81
87
  let(:library) { fake }
82
88
  let(:jake) { Student.new("Jake") }
@@ -94,6 +100,8 @@ Feature: Anonymous test doubles
94
100
  Scenario: Mocking any method with any parameters
95
101
  Then spec file with following content should fail:
96
102
  """ruby
103
+ require_relative 'student'
104
+
97
105
  describe Student do
98
106
  it "allows stubbing any method with any parameters" do
99
107
  library = fake
@@ -105,6 +113,8 @@ Feature: Anonymous test doubles
105
113
  Scenario: Stubbing methods in initializer
106
114
  Then spec file with following content should pass:
107
115
  """ruby
116
+ require_relative 'student'
117
+
108
118
  describe Student do
109
119
  let(:library) { fake(register_junior: "the card") }
110
120
  let(:jake) { Student.new("Jake") }
@@ -120,6 +130,8 @@ Feature: Anonymous test doubles
120
130
  Scenario: Spying on method calls
121
131
  Then spec file with following content should pass:
122
132
  """ruby
133
+ require_relative 'student'
134
+
123
135
  describe Student do
124
136
  let(:library) { fake }
125
137
  let(:jake) { Student.new("Jake") }
@@ -135,6 +147,8 @@ Feature: Anonymous test doubles
135
147
  Scenario: Invoking arbitrary methods
136
148
  Then spec file with following content should pass:
137
149
  """ruby
150
+ require_relative 'student'
151
+
138
152
  describe Student do
139
153
  let(:library) { fake }
140
154