bogus 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/.travis.yml +1 -0
  4. data/Gemfile +0 -2
  5. data/Guardfile +1 -1
  6. data/bogus.gemspec +1 -1
  7. data/features/changelog.md +8 -0
  8. data/features/contract_tests/contract_tests_mocks.feature +4 -4
  9. data/features/contract_tests/contract_tests_stubs.feature +4 -4
  10. data/features/contract_tests/custom_overwritten_class.feature +3 -3
  11. data/features/fakes/fake_objects.feature +2 -2
  12. data/lib/bogus/core_ext.rb +5 -1
  13. data/lib/bogus/rspec/syntax.rb +3 -0
  14. data/lib/bogus/version.rb +1 -1
  15. data/spec/bogus/bugs/rbx_instance_eval_bug_spec.rb +20 -0
  16. data/spec/bogus/bugs/rbx_jruby_stub_on_class_spec.rb +45 -0
  17. data/spec/bogus/contracts/adds_contract_verification_spec.rb +10 -10
  18. data/spec/bogus/contracts/adds_recording_spec.rb +9 -9
  19. data/spec/bogus/contracts/interactions_repository_spec.rb +13 -13
  20. data/spec/bogus/contracts/records_double_interactions_spec.rb +9 -7
  21. data/spec/bogus/contracts/verifies_contracts_spec.rb +9 -9
  22. data/spec/bogus/fakes/copies_classes_spec.rb +5 -5
  23. data/spec/bogus/fakes/creates_fakes_spec.rb +13 -13
  24. data/spec/bogus/fakes/creates_fakes_with_stubbed_methods_spec.rb +21 -19
  25. data/spec/bogus/fakes/fake_ar_attributes_spec.rb +3 -1
  26. data/spec/bogus/fakes/fake_configuration_spec.rb +3 -3
  27. data/spec/bogus/fakes/fakes_classes_spec.rb +6 -6
  28. data/spec/bogus/fakes/faking_factories_spec.rb +3 -1
  29. data/spec/bogus/fakes/frozen_fakes_spec.rb +3 -1
  30. data/spec/bogus/fakes/registers_created_fakes_spec.rb +8 -8
  31. data/spec/bogus/fakes/resets_overwritten_classes_spec.rb +8 -8
  32. data/spec/bogus/fakes/stubbing_new_method_on_fake_class_spec.rb +3 -1
  33. data/spec/bogus/mocking_dsl_spec.rb +3 -1
  34. data/spec/bogus/rspec/syntax_spec.rb +16 -0
  35. data/spec/bogus/ruby_2_1_support_spec.rb +4 -2
  36. data/spec/bogus/ruby_2_support_spec.rb +4 -2
  37. data/spec/bogus/stubbing/double_spec.rb +18 -18
  38. data/spec/bogus/stubbing/have_received_matcher_spec.rb +13 -14
  39. data/spec/bogus/stubbing/interaction_spec.rb +7 -7
  40. data/spec/bogus/stubbing/multi_stubber_spec.rb +5 -5
  41. data/spec/bogus/stubbing/record_interactions_spec.rb +2 -2
  42. data/spec/bogus/stubbing/resets_stubbed_methods_spec.rb +5 -5
  43. data/spec/bogus/stubbing/shadow_spec.rb +6 -6
  44. data/spec/bogus/stubbing/stubbing_existing_methods_on_fakes_spec.rb +1 -1
  45. data/spec/spec_helper.rb +6 -13
  46. data/spec/support/ruby_features.rb +19 -0
  47. metadata +10 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5692979cf19268250f0bd23067c79beca39210f9
4
- data.tar.gz: eace904b3205850ab8a3359453d4fe1236e120fe
3
+ metadata.gz: 4056fb1f5ddc7c47b6e82b777c0d220caff62b21
4
+ data.tar.gz: 3cc4493f6798d729ddc5b14bc9460a1c35632b88
5
5
  SHA512:
6
- metadata.gz: f8be32e8fbc29928cc5f517c10bf6602dee35910e0c2768d83ec0db7c8a62bdd993cc84482aec9d26dd4ecce2f096f80ac0c9bc8ed2c7f6092bf0e570c7fcf54
7
- data.tar.gz: b12ed7d4b58170ff5f7180f559c054817ff7b84476808355d822b7d5270a34083d77f10996036d17d5a45f6da2da80b4e7e4de065e32ab65f244960b1fec43f5
6
+ metadata.gz: c010976d4a8cdf3a2222f467bf41db819bea5178107c8fee3f907cb3648942c15e37f255d49d3bf0d367156a2ff716dff1f56705dbe727ca2571eaeb6702469b
7
+ data.tar.gz: bb1aa720bdd300d3b2ecc6b471f62673ed702deec6159e0e53658f2e3d6a33d5cfc55bdbc60b7418cc12f174e8eda0ac44f823701a85a3efa7657bb43981c0dd
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -4,4 +4,5 @@ rvm:
4
4
  - 2.0
5
5
  - 2.1.1
6
6
  - jruby-19mode
7
+ - rbx
7
8
  script: bundle exec rspec spec && bundle exec cucumber --tag ~@wip
data/Gemfile CHANGED
@@ -2,5 +2,3 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in bogus.gemspec
4
4
  gemspec
5
-
6
- gem 'minitest', require: false
data/Guardfile CHANGED
@@ -1,7 +1,7 @@
1
1
  # A sample Guardfile
2
2
  # More info at https://github.com/guard/guard#readme
3
3
 
4
- guard 'rspec', all_after_pass: true, all_on_start: true do
4
+ guard 'rspec', cmd: 'bundle exec rspec', all_after_pass: true, all_on_start: true do
5
5
  watch(%r{^spec/.+_spec\.rb$})
6
6
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
7
  watch('spec/spec_helper.rb') { "spec" }
@@ -32,9 +32,9 @@ Gem::Specification.new do |s|
32
32
  s.add_development_dependency 'guard-ctags-bundler'
33
33
  s.add_development_dependency 'growl'
34
34
  s.add_development_dependency 'libnotify'
35
- s.add_development_dependency 'rr'
36
35
  s.add_development_dependency 'relish'
37
36
  s.add_development_dependency 'coveralls'
37
+ s.add_development_dependency 'wwtd'
38
38
 
39
39
  s.add_development_dependency 'activerecord', '>= 3', '< 5'
40
40
  s.add_development_dependency 'activerecord-nulldb-adapter'
@@ -1,3 +1,11 @@
1
+ ## 0.1.6
2
+
3
+ - Removed dependency on Coveralls::SimpleCov::Formatter (thanks to Ken Dreyer)
4
+ - Made all tests pass on Rubinious
5
+ - Updated tests to use RSpec Mocks instead of RR in unit tests
6
+ - Updated tests to use RSpec 3
7
+ - Fixed described_class in RSpec 3.*
8
+
1
9
  ## 0.1.5
2
10
 
3
11
  - Made it possible to use fake objects in case/when statements (override ===)
@@ -77,7 +77,7 @@ Feature: Contract tests with mocks
77
77
 
78
78
  library.checkout("Moby Dick")
79
79
 
80
- expect(library.has_book?("Moby Dick")).to be_false
80
+ expect(library.has_book?("Moby Dick")).to be(false)
81
81
  end
82
82
  end
83
83
  """
@@ -95,11 +95,11 @@ Feature: Contract tests with mocks
95
95
  it "allows checking out books that are in the inventory" do
96
96
  library.return("Moby Dick")
97
97
 
98
- expect(library.has_book?("Moby Dick")).to be_true
98
+ expect(library.has_book?("Moby Dick")).to be(true)
99
99
  end
100
100
 
101
101
  it "does not allow checking out unavailable books" do
102
- expect(library.has_book?("Moby Dick")).to be_false
102
+ expect(library.has_book?("Moby Dick")).to be(false)
103
103
  end
104
104
 
105
105
  it "marks books as unavailable after they are checked out" do
@@ -107,7 +107,7 @@ Feature: Contract tests with mocks
107
107
 
108
108
  library.checkout("Moby Dick")
109
109
 
110
- expect(library.has_book?("Moby Dick")).to be_false
110
+ expect(library.has_book?("Moby Dick")).to be(false)
111
111
  end
112
112
  end
113
113
  """
@@ -90,7 +90,7 @@ Feature: Contract tests with stubs
90
90
 
91
91
  library.checkout("Moby Dick")
92
92
 
93
- expect(library.has_book?("Moby Dick")).to be_false
93
+ expect(library.has_book?("Moby Dick")).to be(false)
94
94
  end
95
95
  end
96
96
  """
@@ -108,11 +108,11 @@ Feature: Contract tests with stubs
108
108
  it "allows checking out books that are in the inventory" do
109
109
  library.return("Moby Dick")
110
110
 
111
- expect(library.has_book?("Moby Dick")).to be_true
111
+ expect(library.has_book?("Moby Dick")).to be(true)
112
112
  end
113
113
 
114
114
  it "does not allow checking out unavailable books" do
115
- expect(library.has_book?("Moby Dick")).to be_false
115
+ expect(library.has_book?("Moby Dick")).to be(false)
116
116
  end
117
117
 
118
118
  it "marks books as unavailable after they are checked out" do
@@ -120,7 +120,7 @@ Feature: Contract tests with stubs
120
120
 
121
121
  library.checkout("Moby Dick")
122
122
 
123
- expect(library.has_book?("Moby Dick")).to be_false
123
+ expect(library.has_book?("Moby Dick")).to be(false)
124
124
  end
125
125
  end
126
126
  """
@@ -95,11 +95,11 @@ Feature: Customizing the overwritten class
95
95
  it "allows checking out books that are in the inventory" do
96
96
  library.return("Moby Dick")
97
97
 
98
- expect(library.has_book?("Moby Dick")).to be_true
98
+ expect(library.has_book?("Moby Dick")).to be(true)
99
99
  end
100
100
 
101
101
  it "does not allow checking out unavailable books" do
102
- expect(library.has_book?("Moby Dick")).to be_false
102
+ expect(library.has_book?("Moby Dick")).to be(false)
103
103
  end
104
104
 
105
105
  it "marks books as unavailable after they are checked out" do
@@ -107,7 +107,7 @@ Feature: Customizing the overwritten class
107
107
 
108
108
  library.checkout("Moby Dick")
109
109
 
110
- expect(library.has_book?("Moby Dick")).to be_false
110
+ expect(library.has_book?("Moby Dick")).to be(false)
111
111
  end
112
112
  end
113
113
  """
@@ -60,7 +60,7 @@ Feature: Faking existing classes
60
60
  fake(:library)
61
61
 
62
62
  it "does something" do
63
- expect(Student.learn(library)).to be_true
63
+ expect(Student.learn(library)).to be(true)
64
64
  end
65
65
  end
66
66
  """
@@ -140,7 +140,7 @@ Feature: Faking existing classes
140
140
  fake(:library)
141
141
 
142
142
  it "is identified as Library" do
143
- expect(library?(library)).to be_true
143
+ expect(library?(library)).to be(true)
144
144
  end
145
145
  end
146
146
  """
@@ -1,5 +1,5 @@
1
1
  # This monkey patch should not break Ruby compatibility
2
- # but is necessary because MRI, insead of calling object.kind_of?(module),
2
+ # but is necessary because MRI, instead of calling object.kind_of?(module),
3
3
  # calls the C function, which implements kind_of. This makes
4
4
  # using fake objects in switch cases produce unexpected results:
5
5
  #
@@ -15,7 +15,11 @@
15
15
  class Module
16
16
  # don't warn about redefining === method
17
17
  Bogus::Support.supress_warnings do
18
+ alias :__trequals__ :===
19
+
18
20
  def ===(object)
21
+ # BasicObjects do not have kind_of? method
22
+ return __trequals__(object) unless Object.__trequals__(object)
19
23
  object.kind_of?(self)
20
24
  end
21
25
  end
@@ -8,6 +8,9 @@ module Bogus
8
8
  def_delegators :context, :before, :after, :described_class
9
9
 
10
10
  def described_class=(value)
11
+ # for new RSpec (> 3.0)
12
+ context.metadata[:described_class] = value
13
+ # for old RSpec (< 3.0)
11
14
  context.example.metadata[:example_group][:described_class] = value
12
15
  end
13
16
 
@@ -1,3 +1,3 @@
1
1
  module Bogus
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bogus do
4
+ class SampleForRbxInstanceEval < BasicObject
5
+ def x
6
+ 3
7
+ end
8
+ end
9
+
10
+ it "doesn't break #instance_eval on RBX" do
11
+ result = SampleForRbxInstanceEval.new.instance_eval{x}
12
+ expect(result).to eq(3)
13
+ end
14
+
15
+ it "does not break === with the monkey patch" do
16
+ expect(SampleForRbxInstanceEval === SampleForRbxInstanceEval.new).to be(true)
17
+ expect(BasicObject === SampleForRbxInstanceEval.new).to be(true)
18
+ expect(Bogus === SampleForRbxInstanceEval.new).to be(false)
19
+ end
20
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ class ExampleForRbxJRubyBug
4
+ def self.bar(argument)
5
+ argument
6
+ end
7
+
8
+ def self.foo(argument)
9
+ argument
10
+ end
11
+
12
+ def initialize(*args)
13
+ args
14
+ end
15
+ end
16
+
17
+ describe ExampleForRbxJRubyBug do
18
+ before do
19
+ extend Bogus::MockingDSL
20
+ end
21
+
22
+ context '.bar' do
23
+ specify 'stubbing class twice in example' do
24
+ stub(ExampleForRbxJRubyBug).bar('same_argument')
25
+ stub(ExampleForRbxJRubyBug).bar('same_argument')
26
+ end
27
+ end
28
+
29
+ context '.foo' do
30
+ specify 'stubbing class once in example' do
31
+ stub(ExampleForRbxJRubyBug).foo('same_argument')
32
+ end
33
+
34
+ specify 'stubbing class once in another example' do
35
+ stub(ExampleForRbxJRubyBug).foo('same_argument')
36
+ end
37
+ end
38
+
39
+ context '.new' do
40
+ before { stub(ExampleForRbxJRubyBug).new(any_args) }
41
+
42
+ specify { ExampleForRbxJRubyBug.new(1, 2, 3) }
43
+ specify { ExampleForRbxJRubyBug.new(1, 2, 3) }
44
+ end
45
+ end
@@ -37,7 +37,7 @@ describe Bogus::AddsContractVerification do
37
37
  it "verifies the contract in after_suite" do
38
38
  syntax.run_after_suite
39
39
 
40
- expect(verifies_contracts).to have_received.verify(:some_fake)
40
+ expect(verifies_contracts).to have_received(:verify).with(:some_fake)
41
41
  end
42
42
  end
43
43
 
@@ -49,17 +49,17 @@ describe Bogus::AddsContractVerification do
49
49
 
50
50
  let(:overwritten_class) { :the_overwritten_class }
51
51
 
52
- let(:adds_recording) { stub }
53
- let(:verifies_contracts) { stub }
54
- let(:converts_name_to_class) { stub }
52
+ let(:adds_recording) { double }
53
+ let(:verifies_contracts) { double }
54
+ let(:converts_name_to_class) { double }
55
55
  let(:syntax) { FakeSyntax.new(described_class) }
56
56
 
57
57
  let(:adds_contract_verification) { isolate(Bogus::AddsContractVerification) }
58
58
 
59
59
  before do
60
- stub(adds_recording).add { overwritten_class }
61
- stub(verifies_contracts).verify
62
- stub(converts_name_to_class).convert { ClassGuessedFromFakeName }
60
+ allow(adds_recording).to receive(:add) { overwritten_class }
61
+ allow(verifies_contracts).to receive(:verify)
62
+ allow(converts_name_to_class).to receive(:convert) { ClassGuessedFromFakeName }
63
63
  end
64
64
 
65
65
  context "with described_class" do
@@ -87,7 +87,7 @@ describe Bogus::AddsContractVerification do
87
87
  it "adds recording to described_class" do
88
88
  syntax.run_before
89
89
 
90
- expect(adds_recording).to have_received.add(:some_fake, SomeClass)
90
+ expect(adds_recording).to have_received(:add).with(:some_fake, SomeClass)
91
91
  end
92
92
  end
93
93
 
@@ -119,7 +119,7 @@ describe Bogus::AddsContractVerification do
119
119
  it "adds recording to custom class" do
120
120
  syntax.run_before
121
121
 
122
- expect(adds_recording).to have_received.add(:some_fake, ClassToOverwrite)
122
+ expect(adds_recording).to have_received(:add).with(:some_fake, ClassToOverwrite)
123
123
  end
124
124
  end
125
125
 
@@ -148,7 +148,7 @@ describe Bogus::AddsContractVerification do
148
148
  it "adds recording to class based on fake name" do
149
149
  syntax.run_before
150
150
 
151
- expect(adds_recording).to have_received.add(:some_fake, ClassGuessedFromFakeName)
151
+ expect(adds_recording).to have_received(:add).with(:some_fake, ClassGuessedFromFakeName)
152
152
  end
153
153
  end
154
154
  end
@@ -9,16 +9,16 @@ describe Bogus::AddsRecording do
9
9
  end
10
10
  end
11
11
 
12
- let(:create_proxy_class) { stub }
13
- let(:overwrites_classes) { stub }
14
- let(:overwritten_classes) { stub }
12
+ let(:create_proxy_class) { double }
13
+ let(:overwrites_classes) { double }
14
+ let(:overwritten_classes) { double }
15
15
 
16
16
  let(:adds_recording) { isolate(Bogus::AddsRecording) }
17
17
 
18
18
  before do
19
- stub(create_proxy_class).call { Object }
20
- stub(overwrites_classes).overwrite
21
- stub(overwritten_classes).add
19
+ allow(create_proxy_class).to receive(:call) { Object }
20
+ allow(overwrites_classes).to receive(:overwrite)
21
+ allow(overwritten_classes).to receive(:add)
22
22
  end
23
23
 
24
24
  before do
@@ -26,15 +26,15 @@ describe Bogus::AddsRecording do
26
26
  end
27
27
 
28
28
  it "creates the proxy" do
29
- expect(create_proxy_class).to have_received.call(:library, SampleModule::Library)
29
+ expect(create_proxy_class).to have_received(:call).with(:library, SampleModule::Library)
30
30
  end
31
31
 
32
32
  it "swaps the classes" do
33
- expect(overwrites_classes).to have_received.overwrite('SampleModule::Library', Object)
33
+ expect(overwrites_classes).to have_received(:overwrite).with('SampleModule::Library', Object)
34
34
  end
35
35
 
36
36
  it "records the overwritten class, so that it can be later restored" do
37
- expect(overwritten_classes).to have_received.add("SampleModule::Library", SampleModule::Library)
37
+ expect(overwritten_classes).to have_received(:add).with("SampleModule::Library", SampleModule::Library)
38
38
  end
39
39
 
40
40
  it "returns the proxy class" do
@@ -10,43 +10,43 @@ describe Bogus::InteractionsRepository do
10
10
  it "considers the interaction recorded if it was recorded previously" do
11
11
  interactions_repository.record(:foo, :bar, 1, 2, 3)
12
12
 
13
- expect(recorded?(:foo, :bar, 1, 2, 3)).to be_true
13
+ expect(recorded?(:foo, :bar, 1, 2, 3)).to be(true)
14
14
  end
15
15
 
16
16
  it "considers the interaction recorded if it returned the same value as passed block" do
17
17
  interactions_repository.record(:foo, :bar) { "a result" }
18
18
  interaction = Bogus::Interaction.new(:bar, []) { "a result" }
19
19
 
20
- expect(interactions_repository.recorded?(:foo, interaction)).to be_true
20
+ expect(interactions_repository.recorded?(:foo, interaction)).to be(true)
21
21
  end
22
22
 
23
23
  it "does not consider any interactions recorded prior to any recordings" do
24
- expect(recorded?(:foo, :bar, 1)).to be_false
24
+ expect(recorded?(:foo, :bar, 1)).to be(false)
25
25
  end
26
26
 
27
27
  it "does not consider the interaction recorded with a different fake name" do
28
28
  interactions_repository.record(:baz, :bar, 1)
29
29
 
30
- expect(recorded?(:foo, :bar, 1)).to be_false
30
+ expect(recorded?(:foo, :bar, 1)).to be(false)
31
31
  end
32
32
 
33
33
  it "does not consider the interaction recorded with a different method name" do
34
34
  interactions_repository.record(:foo, :baz, 1)
35
35
 
36
- expect(recorded?(:foo, :bar, 1)).to be_false
36
+ expect(recorded?(:foo, :bar, 1)).to be(false)
37
37
  end
38
38
 
39
39
  it "does not consider the interaction recorded with different method arguments" do
40
40
  interactions_repository.record(:foo, :bar, 1, 2)
41
41
 
42
- expect(recorded?(:foo, :bar, 1)).to be_false
42
+ expect(recorded?(:foo, :bar, 1)).to be(false)
43
43
  end
44
44
 
45
45
  it "returns a list of interactions for given fake" do
46
46
  interactions_repository.record(:foo, :bar, 1, 2)
47
47
 
48
48
  interactions = interactions_repository.for_fake(:foo)
49
- expect(interactions).to have(1).item
49
+ expect(interactions.size).to eq(1)
50
50
  expect(interactions.first.method).to eq :bar
51
51
  expect(interactions.first.args).to eq [1, 2]
52
52
  end
@@ -54,36 +54,36 @@ describe Bogus::InteractionsRepository do
54
54
  it "ignores arguments if the checked interaction has any_args" do
55
55
  interactions_repository.record(:foo, :bar, 1)
56
56
 
57
- expect(recorded?(:foo, :bar, Bogus::AnyArgs)).to be_true
57
+ expect(recorded?(:foo, :bar, Bogus::AnyArgs)).to be(true)
58
58
  end
59
59
 
60
60
  it "takes method name into account when matching interaction with wildcard arguments" do
61
61
  interactions_repository.record(:foo, :baz, 1)
62
62
 
63
- expect(recorded?(:foo, :bar, Bogus::AnyArgs)).to be_false
63
+ expect(recorded?(:foo, :bar, Bogus::AnyArgs)).to be(false)
64
64
  end
65
65
 
66
66
  it "ignores arguments if the recorded interaction was recorded with wildcard argument" do
67
67
  interactions_repository.record(:foo, :bar, 1, 2)
68
68
 
69
- expect(recorded?(:foo, :bar, 1, Bogus::Anything)).to be_true
69
+ expect(recorded?(:foo, :bar, 1, Bogus::Anything)).to be(true)
70
70
  end
71
71
 
72
72
  it "takes other arguments into account when matching interactions with wildcards" do
73
73
  interactions_repository.record(:foo, :bar, 1, 2)
74
74
 
75
- expect(recorded?(:foo, :bar, 2, Bogus::Anything)).to be_false
75
+ expect(recorded?(:foo, :bar, 2, Bogus::Anything)).to be(false)
76
76
  end
77
77
 
78
78
  it "ignores arguments if the checked interaction has any_args" do
79
79
  interactions_repository.record(:foo, :bar, 1, 2)
80
80
 
81
- expect(recorded?(:foo, :bar, 1, Bogus::Anything)).to be_true
81
+ expect(recorded?(:foo, :bar, 1, Bogus::Anything)).to be(true)
82
82
  end
83
83
 
84
84
  it "takes method name into account when matching interaction with wildcard arguments" do
85
85
  interactions_repository.record(:foo, :baz, 1, 2)
86
86
 
87
- expect(recorded?(:foo, :bar, 1, Bogus::Anything)).to be_false
87
+ expect(recorded?(:foo, :bar, 1, Bogus::Anything)).to be(false)
88
88
  end
89
89
  end