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
@@ -1,119 +0,0 @@
|
|
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 "foo.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
|
-
class BookIndex
|
20
|
-
def self.by_author(author)
|
21
|
-
Library.books.select{|book| book[:author] == author}
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class Student
|
26
|
-
def initialize(library)
|
27
|
-
@library = library
|
28
|
-
end
|
29
|
-
|
30
|
-
def study(*book_titles)
|
31
|
-
book_titles.each do |book_title|
|
32
|
-
@library.checkout(book_title)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
"""
|
37
|
-
|
38
|
-
Scenario: Auto-verification of unsatisfied mocks
|
39
|
-
Then minitest file "foo_test.rb" with the following content should fail:
|
40
|
-
"""ruby
|
41
|
-
require 'minitest/autorun'
|
42
|
-
require 'bogus/minitest'
|
43
|
-
require_relative 'foo'
|
44
|
-
|
45
|
-
class StudentTest < MiniTest::Unit::TestCase
|
46
|
-
def test_library_checkouts
|
47
|
-
library = fake(:library)
|
48
|
-
student = Student.new(library)
|
49
|
-
mock(library).checkout("Moby Dick")
|
50
|
-
mock(library).checkout("Sherlock Holmes")
|
51
|
-
|
52
|
-
student.study("Moby Dick")
|
53
|
-
end
|
54
|
-
end
|
55
|
-
"""
|
56
|
-
|
57
|
-
Scenario: Spying on method calls with assert syntax
|
58
|
-
Then minitest file "foo_test.rb" with the following content should pass:
|
59
|
-
"""ruby
|
60
|
-
require 'minitest/autorun'
|
61
|
-
require 'bogus/minitest'
|
62
|
-
require_relative 'foo'
|
63
|
-
|
64
|
-
class StudentTest < MiniTest::Unit::TestCase
|
65
|
-
def setup
|
66
|
-
@library = fake(:library)
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_library_checkouts
|
70
|
-
student = Student.new(@library)
|
71
|
-
|
72
|
-
student.study("Moby Dick", "Sherlock Holmes")
|
73
|
-
|
74
|
-
assert_received @library, :checkout, ["Moby Dick"]
|
75
|
-
assert_received @library, :checkout, ["Sherlock Holmes"]
|
76
|
-
refute_received @library, :return_book, ["Moby Dick"]
|
77
|
-
end
|
78
|
-
end
|
79
|
-
"""
|
80
|
-
|
81
|
-
Scenario: Spying on method calls with expectation syntax
|
82
|
-
Then minitest file "foo_spec.rb" with the following content should pass:
|
83
|
-
"""ruby
|
84
|
-
require 'minitest/autorun'
|
85
|
-
require 'bogus/minitest/spec'
|
86
|
-
require_relative 'foo'
|
87
|
-
|
88
|
-
describe Student do
|
89
|
-
describe "#study" do
|
90
|
-
fake(:library)
|
91
|
-
|
92
|
-
it "studies using books from library" do
|
93
|
-
student = Student.new(library)
|
94
|
-
|
95
|
-
student.study("Moby Dick", "Sherlock Holmes")
|
96
|
-
|
97
|
-
library.must_have_received :checkout, ["Moby Dick"]
|
98
|
-
library.must_have_received :checkout, ["Sherlock Holmes"]
|
99
|
-
library.wont_have_received :return_book, ["Moby Dick"]
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
"""
|
104
|
-
|
105
|
-
Scenario: Describe-level class faking
|
106
|
-
Then minitest file "foo_spec.rb" with the following content should pass:
|
107
|
-
"""ruby
|
108
|
-
require 'minitest/autorun'
|
109
|
-
require 'bogus/minitest/spec'
|
110
|
-
require_relative 'foo'
|
111
|
-
|
112
|
-
describe BookIndex do
|
113
|
-
fake_class(Library, books: [])
|
114
|
-
|
115
|
-
it "returns books written by author" do
|
116
|
-
BookIndex.by_author("Mark Twain").must_equal []
|
117
|
-
end
|
118
|
-
end
|
119
|
-
"""
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module Bogus
|
2
|
-
module RSpecExtensions
|
3
|
-
def fake(name, opts = {}, &block)
|
4
|
-
let(name) { fake(name, opts, &block) }
|
5
|
-
end
|
6
|
-
|
7
|
-
def fake_class(name, opts = {})
|
8
|
-
before do
|
9
|
-
fake_class(name, opts)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def verify_contract(name)
|
14
|
-
old_described_class = described_class
|
15
|
-
|
16
|
-
before do
|
17
|
-
new_class = Bogus.record_calls_for(name, described_class)
|
18
|
-
example.metadata[:example_group][:described_class] = new_class
|
19
|
-
end
|
20
|
-
|
21
|
-
after do
|
22
|
-
example.metadata[:example_group][:described_class] = old_described_class
|
23
|
-
end
|
24
|
-
|
25
|
-
RSpec.configure do |config|
|
26
|
-
config.after(:suite) { Bogus.verify_contract!(name) }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
@@ -1,77 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Bogus::AddsRecording do
|
4
|
-
module SampleModule
|
5
|
-
class Library
|
6
|
-
end
|
7
|
-
|
8
|
-
class OtherClass
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
let(:converts_name_to_class) { stub }
|
13
|
-
let(:create_proxy_class) { stub }
|
14
|
-
let(:overwrites_classes) { stub }
|
15
|
-
let(:overwritten_classes) { stub }
|
16
|
-
|
17
|
-
let(:adds_recording) { isolate(Bogus::AddsRecording) }
|
18
|
-
|
19
|
-
before do
|
20
|
-
stub(converts_name_to_class).convert { SampleModule::Library }
|
21
|
-
stub(create_proxy_class).call { Object }
|
22
|
-
stub(overwrites_classes).overwrite
|
23
|
-
stub(overwritten_classes).add
|
24
|
-
end
|
25
|
-
|
26
|
-
context "without class argument" do
|
27
|
-
before do
|
28
|
-
adds_recording.add(:library)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "converts the fake name to class" do
|
32
|
-
converts_name_to_class.should have_received.convert(:library)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "creates the proxy" do
|
36
|
-
create_proxy_class.should have_received.call(:library, SampleModule::Library)
|
37
|
-
end
|
38
|
-
|
39
|
-
it "swaps the classes" do
|
40
|
-
overwrites_classes.should have_received.overwrite('SampleModule::Library', Object)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "records the overwritten class, so that it can be later restored" do
|
44
|
-
overwritten_classes.should have_received.add("SampleModule::Library", SampleModule::Library)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "returns the proxy class" do
|
48
|
-
adds_recording.add(:library).should == Object
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context "with class argument" do
|
53
|
-
before do
|
54
|
-
adds_recording.add(:library, SampleModule::OtherClass)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "uses the passed class" do
|
58
|
-
converts_name_to_class.should_not have_received.convert(:library)
|
59
|
-
end
|
60
|
-
|
61
|
-
it "creates the proxy" do
|
62
|
-
create_proxy_class.should have_received.call(:library, SampleModule::OtherClass)
|
63
|
-
end
|
64
|
-
|
65
|
-
it "swaps the classes" do
|
66
|
-
overwrites_classes.should have_received.overwrite('SampleModule::OtherClass', Object)
|
67
|
-
end
|
68
|
-
|
69
|
-
it "records the overwritten class, so that it can be later restored" do
|
70
|
-
overwritten_classes.should have_received.add("SampleModule::OtherClass", SampleModule::OtherClass)
|
71
|
-
end
|
72
|
-
|
73
|
-
it "returns the proxy class" do
|
74
|
-
adds_recording.add(:library, SampleModule::OtherClass).should == Object
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|