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
@@ -1,25 +1,27 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Bogus::RecordsDoubleInteractions do
4
- let(:fake_registry) { stub }
5
- let(:doubled_interactions) { stub }
4
+ let(:fake_registry) { double }
5
+ let(:doubled_interactions) { double }
6
6
  let(:object) { Object.new }
7
7
 
8
8
  let(:records_double_interactions) { isolate(Bogus::RecordsDoubleInteractions) }
9
9
 
10
10
  it "records the call in double interaction repository" do
11
- stub(fake_registry).name(object) { :object_name }
12
- stub(doubled_interactions).record
11
+ allow(fake_registry).to receive(:name).with(object) { :object_name }
12
+ allow(doubled_interactions).to receive(:record)
13
13
 
14
14
  records_double_interactions.record(object, :method_name, [:foo, 1])
15
15
 
16
- expect(doubled_interactions).to have_received.record(:object_name, :method_name, :foo, 1)
16
+ expect(doubled_interactions).to have_received(:record).with(:object_name, :method_name, :foo, 1)
17
17
  end
18
18
 
19
19
  it "does not record the interaction if object is not a fake" do
20
- stub(fake_registry).name(object) { nil }
21
- dont_allow(doubled_interactions).record
20
+ allow(fake_registry).to receive(:name).with(object) { nil }
21
+ allow(doubled_interactions).to receive(:record)
22
22
 
23
23
  records_double_interactions.record(object, :method_name, [:foo, 1])
24
+
25
+ expect(doubled_interactions).not_to have_received(:record)
24
26
  end
25
27
  end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Bogus::VerifiesContracts do
4
- let(:real_interactions) { stub }
5
- let(:doubled_interactions) { stub }
4
+ let(:real_interactions) { double }
5
+ let(:doubled_interactions) { double }
6
6
  let(:verifies_contracts) { isolate(Bogus::VerifiesContracts) }
7
7
 
8
8
  let(:matched_interaction) { interaction("matched") }
@@ -12,12 +12,12 @@ describe Bogus::VerifiesContracts do
12
12
  second_interaction = interaction("second")
13
13
  other_interaction = interaction("other")
14
14
 
15
- stub(doubled_interactions).for_fake(:fake_name){[first_interaction, matched_interaction, second_interaction]}
16
- stub(real_interactions).for_fake(:fake_name){[matched_interaction, other_interaction]}
15
+ allow(doubled_interactions).to receive(:for_fake).with(:fake_name){[first_interaction, matched_interaction, second_interaction]}
16
+ allow(real_interactions).to receive(:for_fake).with(:fake_name){[matched_interaction, other_interaction]}
17
17
 
18
- stub(real_interactions).recorded?(:fake_name, first_interaction) { false }
19
- stub(real_interactions).recorded?(:fake_name, second_interaction) { false }
20
- stub(real_interactions).recorded?(:fake_name, matched_interaction) { true }
18
+ allow(real_interactions).to receive(:recorded?).with(:fake_name, first_interaction) { false }
19
+ allow(real_interactions).to receive(:recorded?).with(:fake_name, second_interaction) { false }
20
+ allow(real_interactions).to receive(:recorded?).with(:fake_name, matched_interaction) { true }
21
21
 
22
22
  expect_verify_to_raise_error_with_interactions(:fake_name,
23
23
  [first_interaction, second_interaction],
@@ -25,8 +25,8 @@ describe Bogus::VerifiesContracts do
25
25
  end
26
26
 
27
27
  it "passes with all calls matched" do
28
- stub(doubled_interactions).for_fake(:fake_name) { [matched_interaction] }
29
- stub(real_interactions).recorded?(:fake_name, matched_interaction) { true }
28
+ allow(doubled_interactions).to receive(:for_fake).with(:fake_name) { [matched_interaction] }
29
+ allow(real_interactions).to receive(:recorded?).with(:fake_name, matched_interaction) { true }
30
30
 
31
31
  expect {
32
32
  verifies_contracts.verify(:fake_name)
@@ -125,15 +125,15 @@ describe Bogus::CopiesClasses do
125
125
  end
126
126
 
127
127
  it "should override kind_of?" do
128
- expect(fake.kind_of?(SomeModule::SomeClass)).to be_true
128
+ expect(fake.kind_of?(SomeModule::SomeClass)).to be(true)
129
129
  end
130
130
 
131
131
  it "should override instance_of?" do
132
- expect(fake.instance_of?(SomeModule::SomeClass)).to be_true
132
+ expect(fake.instance_of?(SomeModule::SomeClass)).to be(true)
133
133
  end
134
134
 
135
135
  it "should override is_a?" do
136
- expect(fake.is_a?(SomeModule::SomeClass)).to be_true
136
+ expect(fake.is_a?(SomeModule::SomeClass)).to be(true)
137
137
  end
138
138
 
139
139
  it "should include class name in the output of fake's class #to_s" do
@@ -145,13 +145,13 @@ describe Bogus::CopiesClasses do
145
145
  end
146
146
 
147
147
  it 'should override ===' do
148
- expect(SomeModule::SomeClass === fake).to be_true
148
+ expect(SomeModule::SomeClass === fake).to be(true)
149
149
  end
150
150
  end
151
151
 
152
152
  shared_examples_for 'spying' do
153
153
  def should_record(method, *args)
154
- mock(subject).__record__(method, *args)
154
+ expect(subject).to receive(:__record__).with(method, *args)
155
155
 
156
156
  subject.send(method, *args)
157
157
  end
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Bogus::CreatesFakes do
4
- let(:fake_class) { stub }
5
- let(:fake_instance) { stub }
6
- let(:converts_name_to_class) { stub }
7
- let(:copies_classes) { stub }
8
- let(:makes_ducks) { stub }
4
+ let(:fake_class) { double }
5
+ let(:fake_instance) { double }
6
+ let(:converts_name_to_class) { double }
7
+ let(:copies_classes) { double }
8
+ let(:makes_ducks) { double }
9
9
  let(:creates_fakes) { isolate(Bogus::CreatesFakes) }
10
10
 
11
11
  module Foo
@@ -14,12 +14,12 @@ describe Bogus::CreatesFakes do
14
14
  module Bar
15
15
  end
16
16
 
17
- before { stub(fake_class).__create__{fake_instance} }
17
+ before { allow(fake_class).to receive(:__create__){fake_instance} }
18
18
 
19
19
  context "without block" do
20
20
  before do
21
- mock(converts_name_to_class).convert(:foo) { Foo }
22
- mock(copies_classes).copy(Foo) { fake_class }
21
+ expect(converts_name_to_class).to receive(:convert).with(:foo) { Foo }
22
+ expect(copies_classes).to receive(:copy).with(Foo) { fake_class }
23
23
  end
24
24
 
25
25
  it "creates a new instance of copied class by default" do
@@ -43,8 +43,8 @@ describe Bogus::CreatesFakes do
43
43
 
44
44
  context "with block" do
45
45
  before do
46
- stub(converts_name_to_class).convert
47
- mock(copies_classes).copy(Bar) { fake_class }
46
+ allow(converts_name_to_class).to receive(:convert)
47
+ expect(copies_classes).to receive(:copy).with(Bar) { fake_class }
48
48
  end
49
49
 
50
50
  it "uses the class provided" do
@@ -54,7 +54,7 @@ describe Bogus::CreatesFakes do
54
54
  it "does not convert the class name" do
55
55
  creates_fakes.create(:foo) { Bar}
56
56
 
57
- expect(copies_classes).to_not have_received.convert
57
+ expect(converts_name_to_class).not_to have_received(:convert)
58
58
  end
59
59
  end
60
60
 
@@ -63,8 +63,8 @@ describe Bogus::CreatesFakes do
63
63
 
64
64
  context "with multiple classes" do
65
65
  it "creates a duck type out of those classes and fakes it" do
66
- stub(makes_ducks).make(Foo, Bar) { FooBarDuck }
67
- stub(copies_classes).copy(FooBarDuck) { :the_fake }
66
+ allow(makes_ducks).to receive(:make).with(Foo, Bar) { FooBarDuck }
67
+ allow(copies_classes).to receive(:copy).with(FooBarDuck) { :the_fake }
68
68
 
69
69
  fake = creates_fakes.create(:role, as: :class) { [Foo, Bar] }
70
70
 
@@ -3,15 +3,15 @@ require 'spec_helper'
3
3
  module Bogus
4
4
  describe CreatesFakesWithStubbedMethods do
5
5
  let(:creates_fakes) { FakeCreatorOfFakes.new }
6
- let(:fake_configuration) { stub }
7
- let(:responds_to_everything) { stub }
8
- let(:multi_stubber) { stub }
6
+ let(:fake_configuration) { double }
7
+ let(:responds_to_everything) { double }
8
+ let(:multi_stubber) { double }
9
9
 
10
10
  let(:creates_anonymous_stubs) { isolate(CreatesFakesWithStubbedMethods) }
11
11
 
12
12
  before do
13
- stub(fake_configuration).include? { false }
14
- stub(multi_stubber).stub_all { :stubbed_object }
13
+ allow(fake_configuration).to receive(:include?) { false }
14
+ allow(multi_stubber).to receive(:stub_all) { :stubbed_object }
15
15
  end
16
16
 
17
17
  context "given symbol as first parameter" do
@@ -26,7 +26,7 @@ module Bogus
26
26
  end
27
27
 
28
28
  it "stubs all the given methods" do
29
- expect(multi_stubber).to have_received.stub_all(fake, bar: 1)
29
+ expect(multi_stubber).to have_received(:stub_all).with(fake, bar: 1)
30
30
  end
31
31
  end
32
32
 
@@ -40,7 +40,7 @@ module Bogus
40
40
  end
41
41
 
42
42
  it "stubs all the given methods" do
43
- expect(multi_stubber).to have_received.stub_all(responds_to_everything, bar: 1)
43
+ expect(multi_stubber).to have_received(:stub_all).with(responds_to_everything, bar: 1)
44
44
  end
45
45
  end
46
46
 
@@ -56,7 +56,7 @@ module Bogus
56
56
  end
57
57
 
58
58
  it "stubs all the given methods" do
59
- expect(multi_stubber).to have_received.stub_all(fake, {})
59
+ expect(multi_stubber).to have_received(:stub_all).with(fake, {})
60
60
  end
61
61
  end
62
62
 
@@ -70,7 +70,7 @@ module Bogus
70
70
  end
71
71
 
72
72
  it "stubs all the given methods" do
73
- expect(multi_stubber).to have_received.stub_all(responds_to_everything, {})
73
+ expect(multi_stubber).to have_received(:stub_all).with(responds_to_everything, {})
74
74
  end
75
75
  end
76
76
 
@@ -78,8 +78,8 @@ module Bogus
78
78
  let(:fake) { [:foo, {as: :class}, "SomeClass"] }
79
79
 
80
80
  before do
81
- stub(fake_configuration).include?(:foo) { true }
82
- stub(fake_configuration).get(:foo) { FakeDefinition.new(opts: {as: :class},
81
+ allow(fake_configuration).to receive(:include?).with(:foo) { true }
82
+ allow(fake_configuration).to receive(:get).with(:foo) { FakeDefinition.new(opts: {as: :class},
83
83
  stubs: {xyz: "abc"},
84
84
  class_block: proc{"SomeClass"}) }
85
85
 
@@ -89,12 +89,12 @@ module Bogus
89
89
  it "uses the configuration to create fake" do
90
90
  expect(creates_fakes.fakes).to eq [fake]
91
91
 
92
- expect(fake_configuration).to have_received.include?(:foo)
93
- expect(fake_configuration).to have_received.get(:foo)
92
+ expect(fake_configuration).to have_received(:include?).with(:foo)
93
+ expect(fake_configuration).to have_received(:get).with(:foo)
94
94
  end
95
95
 
96
96
  it "stubs the methods defined in configuration" do
97
- expect(multi_stubber).to have_received.stub_all(fake, xyz: "abc")
97
+ expect(multi_stubber).to have_received(:stub_all).with(fake, xyz: "abc")
98
98
  end
99
99
  end
100
100
 
@@ -102,10 +102,12 @@ module Bogus
102
102
  let(:fake) { [:foo, {as: :instance}, "SomeOtherClass"] }
103
103
 
104
104
  before do
105
- stub(fake_configuration).include?(:foo) { true }
106
- stub(fake_configuration).get(:foo) { FakeDefinition.new(opts: {as: :class},
107
- stubs: {a: "b", b: "c"},
108
- class_block: proc{"SomeClass"}) }
105
+ allow(fake_configuration).to receive(:include?).with(:foo) { true }
106
+ allow(fake_configuration).to receive(:get).with(:foo) {
107
+ FakeDefinition.new(opts: {as: :class},
108
+ stubs: {a: "b", b: "c"},
109
+ class_block: proc{"SomeClass"})
110
+ }
109
111
 
110
112
  creates_anonymous_stubs.create(:foo, as: :instance, b: "d", c: "e") { "SomeOtherClass" }
111
113
  end
@@ -115,7 +117,7 @@ module Bogus
115
117
  end
116
118
 
117
119
  it "overrides the stubbed methods" do
118
- expect(multi_stubber).to have_received.stub_all(fake, a: "b", b: "d", c: "e")
120
+ expect(multi_stubber).to have_received(:stub_all).with(fake, a: "b", b: "d", c: "e")
119
121
  end
120
122
  end
121
123
  end
@@ -19,7 +19,9 @@ describe "Stubbing ActiveRecord::Base subclasses" do
19
19
  end
20
20
  end
21
21
 
22
- include Bogus::MockingDSL
22
+ before do
23
+ extend Bogus::MockingDSL
24
+ end
23
25
 
24
26
  before do
25
27
  Bogus.configure do |c|
@@ -4,7 +4,7 @@ describe Bogus::FakeConfiguration do
4
4
  let(:config) { Bogus::FakeConfiguration.new }
5
5
 
6
6
  it "does not contain not configured fakes" do
7
- expect(config.include?(:foo)).to be_false
7
+ expect(config.include?(:foo)).to be(false)
8
8
  end
9
9
 
10
10
  def class_block(name)
@@ -26,8 +26,8 @@ describe Bogus::FakeConfiguration do
26
26
  end
27
27
  end
28
28
 
29
- expect(config.include?(:foo)).to be_true
30
- expect(config.include?(:bar)).to be_false
29
+ expect(config.include?(:foo)).to be(true)
30
+ expect(config.include?(:bar)).to be(false)
31
31
  end
32
32
 
33
33
  it "returns the configuration for a fake" do
@@ -2,8 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe Bogus::FakesClasses do
4
4
  let(:creates_fakes_with_stubbed_methods) { FakeCreatorOfFakes.new }
5
- let(:overwrites_classes) { stub }
6
- let(:overwritten_classes) { stub }
5
+ let(:overwrites_classes) { double }
6
+ let(:overwritten_classes) { double }
7
7
 
8
8
  let(:fakes_classes) { isolate(Bogus::FakesClasses) }
9
9
 
@@ -13,8 +13,8 @@ describe Bogus::FakesClasses do
13
13
  end
14
14
 
15
15
  before do
16
- stub(overwrites_classes).overwrite
17
- stub(overwritten_classes).add
16
+ allow(overwrites_classes).to receive(:overwrite)
17
+ allow(overwritten_classes).to receive(:add)
18
18
  end
19
19
 
20
20
  it "creates a fake named after the class" do
@@ -29,13 +29,13 @@ describe Bogus::FakesClasses do
29
29
 
30
30
  fakes_classes.fake(Samples::WillBeOverwritten)
31
31
 
32
- expect(overwrites_classes).to have_received.overwrite("Samples::WillBeOverwritten", fake)
32
+ expect(overwrites_classes).to have_received(:overwrite).with("Samples::WillBeOverwritten", fake)
33
33
  end
34
34
 
35
35
  it "stores the overwritten class so that it can be replaced back later" do
36
36
  fakes_classes.fake(Samples::WillBeOverwritten)
37
37
 
38
- expect(overwritten_classes).to have_received.add("Samples::WillBeOverwritten", Samples::WillBeOverwritten)
38
+ expect(overwritten_classes).to have_received(:add).with("Samples::WillBeOverwritten", Samples::WillBeOverwritten)
39
39
  end
40
40
 
41
41
  it "uses the passed fake name if provided" do
@@ -1,7 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "Faking Factories" do
4
- include Bogus::MockingDSL
4
+ before do
5
+ extend Bogus::MockingDSL
6
+ end
5
7
 
6
8
  class ExampleFactory
7
9
  def initialize(model_class)
@@ -1,7 +1,9 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe "Frozen Fakes" do
4
- include Bogus::MockingDSL
4
+ before do
5
+ extend Bogus::MockingDSL
6
+ end
5
7
 
6
8
  class ExampleForFreezing
7
9
  def foo(x)
@@ -1,28 +1,28 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Bogus::RegistersCreatedFakes do
4
- let(:fake_registry) { stub }
5
- let(:creates_fakes) { stub }
6
- let(:double_tracker) { stub }
4
+ let(:fake_registry) { double }
5
+ let(:creates_fakes) { double }
6
+ let(:double_tracker) { double }
7
7
 
8
8
  let(:registers_created_fakes) { isolate(Bogus::RegistersCreatedFakes) }
9
9
 
10
10
  before do
11
- stub(fake_registry).store
12
- stub(creates_fakes).create { :the_fake }
13
- stub(double_tracker).track(:the_fake)
11
+ allow(fake_registry).to receive(:store)
12
+ allow(creates_fakes).to receive(:create) { :the_fake }
13
+ allow(double_tracker).to receive(:track).with(:the_fake)
14
14
  end
15
15
 
16
16
  it "registers the fakes created by creates_fakes" do
17
17
  registers_created_fakes.create(:foo, as: :instance) { Object }
18
18
 
19
- expect(fake_registry).to have_received.store(:foo, :the_fake)
19
+ expect(fake_registry).to have_received(:store).with(:foo, :the_fake)
20
20
  end
21
21
 
22
22
  it "tracks the created fakes for purposes of mock expectations" do
23
23
  registers_created_fakes.create(:foo, as: :instance) { Object }
24
24
 
25
- expect(double_tracker).to have_received.track(:the_fake)
25
+ expect(double_tracker).to have_received(:track).with(:the_fake)
26
26
  end
27
27
 
28
28
  it "returns the created fake" do
@@ -2,25 +2,25 @@ require 'spec_helper'
2
2
 
3
3
  describe Bogus::ResetsOverwrittenClasses do
4
4
  let(:classes) { [['Foo', :foo], ['Bar', :bar]] }
5
- let(:overwritten_classes) { stub }
6
- let(:overwrites_classes) { stub }
5
+ let(:overwritten_classes) { double }
6
+ let(:overwrites_classes) { double }
7
7
 
8
8
  let(:resets_overwritten_classes) { isolate(Bogus::ResetsOverwrittenClasses) }
9
9
 
10
10
  before do
11
- stub(overwritten_classes).classes { classes }
12
- stub(overwritten_classes).clear
13
- stub(overwrites_classes).overwrite
11
+ allow(overwritten_classes).to receive(:classes) { classes }
12
+ allow(overwritten_classes).to receive(:clear)
13
+ allow(overwrites_classes).to receive(:overwrite)
14
14
 
15
15
  resets_overwritten_classes.reset
16
16
  end
17
17
 
18
18
  it "overwrites back all of the overwritten classes" do
19
- expect(overwrites_classes).to have_received.overwrite('Foo', :foo)
20
- expect(overwrites_classes).to have_received.overwrite('Bar', :bar)
19
+ expect(overwrites_classes).to have_received(:overwrite).with('Foo', :foo)
20
+ expect(overwrites_classes).to have_received(:overwrite).with('Bar', :bar)
21
21
  end
22
22
 
23
23
  it "clears the overwritten classes" do
24
- expect(overwritten_classes).to have_received.clear
24
+ expect(overwritten_classes).to have_received(:clear)
25
25
  end
26
26
  end
@@ -4,7 +4,9 @@ describe "Stubbing .new on fake class" do
4
4
  class ExampleForStubbingNew
5
5
  end
6
6
 
7
- include Bogus::MockingDSL
7
+ before do
8
+ extend Bogus::MockingDSL
9
+ end
8
10
 
9
11
  it "allows stubbing new on a class" do
10
12
  fake_class = fake(ExampleForStubbingNew, as: :class)