[DRE-commits] [ruby-bogus] 01/07: Imported Upstream version 0.1.6
Cédric Boutillier
boutil at moszumanska.debian.org
Sun Mar 13 20:42:27 UTC 2016
This is an automated email from the git hooks/post-receive script.
boutil pushed a commit to branch master
in repository ruby-bogus.
commit beccef8ef558f16ecc76dec26bb53147e7e61184
Author: Cédric Boutillier <boutil at debian.org>
Date: Sun Aug 9 23:25:03 2015 +0200
Imported Upstream version 0.1.6
---
.rspec | 1 +
.travis.yml | 1 +
Gemfile | 2 -
Guardfile | 2 +-
bogus.gemspec | 2 +-
checksums.yaml.gz | Bin 269 -> 0 bytes
features/changelog.md | 8 ++++
.../contract_tests/contract_tests_mocks.feature | 8 ++--
.../contract_tests/contract_tests_stubs.feature | 8 ++--
.../custom_overwritten_class.feature | 6 +--
features/fakes/fake_objects.feature | 4 +-
lib/bogus/core_ext.rb | 6 ++-
lib/bogus/rspec/syntax.rb | 3 ++
lib/bogus/version.rb | 2 +-
metadata.yml | 15 ++++---
spec/bogus/bugs/rbx_instance_eval_bug_spec.rb | 20 +++++++++
spec/bogus/bugs/rbx_jruby_stub_on_class_spec.rb | 45 +++++++++++++++++++++
.../contracts/adds_contract_verification_spec.rb | 20 ++++-----
spec/bogus/contracts/adds_recording_spec.rb | 18 ++++-----
.../contracts/interactions_repository_spec.rb | 26 ++++++------
.../contracts/records_double_interactions_spec.rb | 16 ++++----
spec/bogus/contracts/verifies_contracts_spec.rb | 18 ++++-----
spec/bogus/fakes/copies_classes_spec.rb | 10 ++---
spec/bogus/fakes/creates_fakes_spec.rb | 26 ++++++------
.../creates_fakes_with_stubbed_methods_spec.rb | 40 +++++++++---------
spec/bogus/fakes/fake_ar_attributes_spec.rb | 4 +-
spec/bogus/fakes/fake_configuration_spec.rb | 6 +--
spec/bogus/fakes/fakes_classes_spec.rb | 12 +++---
spec/bogus/fakes/faking_factories_spec.rb | 4 +-
spec/bogus/fakes/frozen_fakes_spec.rb | 4 +-
spec/bogus/fakes/registers_created_fakes_spec.rb | 16 ++++----
.../bogus/fakes/resets_overwritten_classes_spec.rb | 16 ++++----
.../stubbing_new_method_on_fake_class_spec.rb | 4 +-
spec/bogus/mocking_dsl_spec.rb | 4 +-
spec/bogus/rspec/syntax_spec.rb | 16 ++++++++
spec/bogus/ruby_2_1_support_spec.rb | 6 ++-
spec/bogus/ruby_2_support_spec.rb | 6 ++-
spec/bogus/stubbing/double_spec.rb | 36 ++++++++---------
spec/bogus/stubbing/have_received_matcher_spec.rb | 27 ++++++-------
spec/bogus/stubbing/interaction_spec.rb | 14 +++----
spec/bogus/stubbing/multi_stubber_spec.rb | 10 ++---
spec/bogus/stubbing/record_interactions_spec.rb | 4 +-
spec/bogus/stubbing/resets_stubbed_methods_spec.rb | 10 ++---
spec/bogus/stubbing/shadow_spec.rb | 12 +++---
.../stubbing_existing_methods_on_fakes_spec.rb | 2 +-
spec/spec_helper.rb | 19 +++------
spec/support/ruby_features.rb | 19 +++++++++
47 files changed, 344 insertions(+), 214 deletions(-)
diff --git a/.rspec b/.rspec
new file mode 100644
index 0000000..4e1e0d2
--- /dev/null
+++ b/.rspec
@@ -0,0 +1 @@
+--color
diff --git a/.travis.yml b/.travis.yml
index b3bedc9..9a23dd9 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,4 +4,5 @@ rvm:
- 2.0
- 2.1.1
- jruby-19mode
+ - rbx
script: bundle exec rspec spec && bundle exec cucumber --tag ~@wip
diff --git a/Gemfile b/Gemfile
index 92bd043..f8323e5 100644
--- a/Gemfile
+++ b/Gemfile
@@ -2,5 +2,3 @@ source "http://rubygems.org"
# Specify your gem's dependencies in bogus.gemspec
gemspec
-
-gem 'minitest', require: false
diff --git a/Guardfile b/Guardfile
index 2f819f8..c2ce9c4 100644
--- a/Guardfile
+++ b/Guardfile
@@ -1,7 +1,7 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
-guard 'rspec', all_after_pass: true, all_on_start: true do
+guard 'rspec', cmd: 'bundle exec rspec', all_after_pass: true, all_on_start: true do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
diff --git a/bogus.gemspec b/bogus.gemspec
index 74a01b4..50fe8ab 100644
--- a/bogus.gemspec
+++ b/bogus.gemspec
@@ -32,9 +32,9 @@ Gem::Specification.new do |s|
s.add_development_dependency 'guard-ctags-bundler'
s.add_development_dependency 'growl'
s.add_development_dependency 'libnotify'
- s.add_development_dependency 'rr'
s.add_development_dependency 'relish'
s.add_development_dependency 'coveralls'
+ s.add_development_dependency 'wwtd'
s.add_development_dependency 'activerecord', '>= 3', '< 5'
s.add_development_dependency 'activerecord-nulldb-adapter'
diff --git a/checksums.yaml.gz b/checksums.yaml.gz
deleted file mode 100644
index af6464f..0000000
Binary files a/checksums.yaml.gz and /dev/null differ
diff --git a/features/changelog.md b/features/changelog.md
index cf241c0..414f183 100644
--- a/features/changelog.md
+++ b/features/changelog.md
@@ -1,3 +1,11 @@
+## 0.1.6
+
+- Removed dependency on Coveralls::SimpleCov::Formatter (thanks to Ken Dreyer)
+- Made all tests pass on Rubinious
+- Updated tests to use RSpec Mocks instead of RR in unit tests
+- Updated tests to use RSpec 3
+- Fixed described_class in RSpec 3.*
+
## 0.1.5
- Made it possible to use fake objects in case/when statements (override ===)
diff --git a/features/contract_tests/contract_tests_mocks.feature b/features/contract_tests/contract_tests_mocks.feature
index a90e84f..f8bee1e 100644
--- a/features/contract_tests/contract_tests_mocks.feature
+++ b/features/contract_tests/contract_tests_mocks.feature
@@ -77,7 +77,7 @@ Feature: Contract tests with mocks
library.checkout("Moby Dick")
- expect(library.has_book?("Moby Dick")).to be_false
+ expect(library.has_book?("Moby Dick")).to be(false)
end
end
"""
@@ -95,11 +95,11 @@ Feature: Contract tests with mocks
it "allows checking out books that are in the inventory" do
library.return("Moby Dick")
- expect(library.has_book?("Moby Dick")).to be_true
+ expect(library.has_book?("Moby Dick")).to be(true)
end
it "does not allow checking out unavailable books" do
- expect(library.has_book?("Moby Dick")).to be_false
+ expect(library.has_book?("Moby Dick")).to be(false)
end
it "marks books as unavailable after they are checked out" do
@@ -107,7 +107,7 @@ Feature: Contract tests with mocks
library.checkout("Moby Dick")
- expect(library.has_book?("Moby Dick")).to be_false
+ expect(library.has_book?("Moby Dick")).to be(false)
end
end
"""
diff --git a/features/contract_tests/contract_tests_stubs.feature b/features/contract_tests/contract_tests_stubs.feature
index 02bb6bb..f561182 100644
--- a/features/contract_tests/contract_tests_stubs.feature
+++ b/features/contract_tests/contract_tests_stubs.feature
@@ -90,7 +90,7 @@ Feature: Contract tests with stubs
library.checkout("Moby Dick")
- expect(library.has_book?("Moby Dick")).to be_false
+ expect(library.has_book?("Moby Dick")).to be(false)
end
end
"""
@@ -108,11 +108,11 @@ Feature: Contract tests with stubs
it "allows checking out books that are in the inventory" do
library.return("Moby Dick")
- expect(library.has_book?("Moby Dick")).to be_true
+ expect(library.has_book?("Moby Dick")).to be(true)
end
it "does not allow checking out unavailable books" do
- expect(library.has_book?("Moby Dick")).to be_false
+ expect(library.has_book?("Moby Dick")).to be(false)
end
it "marks books as unavailable after they are checked out" do
@@ -120,7 +120,7 @@ Feature: Contract tests with stubs
library.checkout("Moby Dick")
- expect(library.has_book?("Moby Dick")).to be_false
+ expect(library.has_book?("Moby Dick")).to be(false)
end
end
"""
diff --git a/features/contract_tests/custom_overwritten_class.feature b/features/contract_tests/custom_overwritten_class.feature
index 5b6f803..200da4f 100644
--- a/features/contract_tests/custom_overwritten_class.feature
+++ b/features/contract_tests/custom_overwritten_class.feature
@@ -95,11 +95,11 @@ Feature: Customizing the overwritten class
it "allows checking out books that are in the inventory" do
library.return("Moby Dick")
- expect(library.has_book?("Moby Dick")).to be_true
+ expect(library.has_book?("Moby Dick")).to be(true)
end
it "does not allow checking out unavailable books" do
- expect(library.has_book?("Moby Dick")).to be_false
+ expect(library.has_book?("Moby Dick")).to be(false)
end
it "marks books as unavailable after they are checked out" do
@@ -107,7 +107,7 @@ Feature: Customizing the overwritten class
library.checkout("Moby Dick")
- expect(library.has_book?("Moby Dick")).to be_false
+ expect(library.has_book?("Moby Dick")).to be(false)
end
end
"""
diff --git a/features/fakes/fake_objects.feature b/features/fakes/fake_objects.feature
index 648472f..6dac994 100644
--- a/features/fakes/fake_objects.feature
+++ b/features/fakes/fake_objects.feature
@@ -60,7 +60,7 @@ Feature: Faking existing classes
fake(:library)
it "does something" do
- expect(Student.learn(library)).to be_true
+ expect(Student.learn(library)).to be(true)
end
end
"""
@@ -140,7 +140,7 @@ Feature: Faking existing classes
fake(:library)
it "is identified as Library" do
- expect(library?(library)).to be_true
+ expect(library?(library)).to be(true)
end
end
"""
diff --git a/lib/bogus/core_ext.rb b/lib/bogus/core_ext.rb
index f0c8f7b..c8cad75 100644
--- a/lib/bogus/core_ext.rb
+++ b/lib/bogus/core_ext.rb
@@ -1,5 +1,5 @@
# This monkey patch should not break Ruby compatibility
-# but is necessary because MRI, insead of calling object.kind_of?(module),
+# but is necessary because MRI, instead of calling object.kind_of?(module),
# calls the C function, which implements kind_of. This makes
# using fake objects in switch cases produce unexpected results:
#
@@ -15,7 +15,11 @@
class Module
# don't warn about redefining === method
Bogus::Support.supress_warnings do
+ alias :__trequals__ :===
+
def ===(object)
+ # BasicObjects do not have kind_of? method
+ return __trequals__(object) unless Object.__trequals__(object)
object.kind_of?(self)
end
end
diff --git a/lib/bogus/rspec/syntax.rb b/lib/bogus/rspec/syntax.rb
index 0d01cb5..56726a7 100644
--- a/lib/bogus/rspec/syntax.rb
+++ b/lib/bogus/rspec/syntax.rb
@@ -8,6 +8,9 @@ module Bogus
def_delegators :context, :before, :after, :described_class
def described_class=(value)
+ # for new RSpec (> 3.0)
+ context.metadata[:described_class] = value
+ # for old RSpec (< 3.0)
context.example.metadata[:example_group][:described_class] = value
end
diff --git a/lib/bogus/version.rb b/lib/bogus/version.rb
index 8b7e98c..f71d0ed 100644
--- a/lib/bogus/version.rb
+++ b/lib/bogus/version.rb
@@ -1,3 +1,3 @@
module Bogus
- VERSION = "0.1.5"
+ VERSION = "0.1.6"
end
diff --git a/metadata.yml b/metadata.yml
index 57fcd92..cca8dfe 100644
--- a/metadata.yml
+++ b/metadata.yml
@@ -1,14 +1,14 @@
--- !ruby/object:Gem::Specification
name: bogus
version: !ruby/object:Gem::Version
- version: 0.1.5
+ version: 0.1.6
platform: ruby
authors:
- Adam Pohorecki
autorequire:
bindir: bin
cert_chain: []
-date: 2014-04-29 00:00:00.000000000 Z
+date: 2015-01-02 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
name: dependor
@@ -165,7 +165,7 @@ dependencies:
- !ruby/object:Gem::Version
version: '0'
- !ruby/object:Gem::Dependency
- name: rr
+ name: relish
requirement: !ruby/object:Gem::Requirement
requirements:
- - ">="
@@ -179,7 +179,7 @@ dependencies:
- !ruby/object:Gem::Version
version: '0'
- !ruby/object:Gem::Dependency
- name: relish
+ name: coveralls
requirement: !ruby/object:Gem::Requirement
requirements:
- - ">="
@@ -193,7 +193,7 @@ dependencies:
- !ruby/object:Gem::Version
version: '0'
- !ruby/object:Gem::Dependency
- name: coveralls
+ name: wwtd
requirement: !ruby/object:Gem::Requirement
requirements:
- - ">="
@@ -278,6 +278,7 @@ extra_rdoc_files: []
files:
- ".gitignore"
- ".pelusa.yml"
+- ".rspec"
- ".travis.yml"
- Gemfile
- Guardfile
@@ -386,6 +387,8 @@ files:
- license.md
- pelusa.sh
- rbs.sh
+- spec/bogus/bugs/rbx_instance_eval_bug_spec.rb
+- spec/bogus/bugs/rbx_jruby_stub_on_class_spec.rb
- spec/bogus/clean_ruby_spec.rb
- spec/bogus/configuration_spec.rb
- spec/bogus/contracts/adds_contract_verification_spec.rb
@@ -417,6 +420,7 @@ files:
- spec/bogus/fakes/resets_overwritten_classes_spec.rb
- spec/bogus/fakes/stubbing_new_method_on_fake_class_spec.rb
- spec/bogus/mocking_dsl_spec.rb
+- spec/bogus/rspec/syntax_spec.rb
- spec/bogus/ruby_2_1_support_spec.rb
- spec/bogus/ruby_2_support_spec.rb
- spec/bogus/stubbing/anything_spec.rb
@@ -436,6 +440,7 @@ files:
- spec/spec_helper.rb
- spec/support/fake_creator_of_fakes.rb
- spec/support/matchers.rb
+- spec/support/ruby_features.rb
- spec/support/sample_fake.rb
- spec/support/shared_examples_for_keyword_arguments.rb
homepage: https://github.com/psyho/bogus
diff --git a/spec/bogus/bugs/rbx_instance_eval_bug_spec.rb b/spec/bogus/bugs/rbx_instance_eval_bug_spec.rb
new file mode 100644
index 0000000..9765c76
--- /dev/null
+++ b/spec/bogus/bugs/rbx_instance_eval_bug_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe Bogus do
+ class SampleForRbxInstanceEval < BasicObject
+ def x
+ 3
+ end
+ end
+
+ it "doesn't break #instance_eval on RBX" do
+ result = SampleForRbxInstanceEval.new.instance_eval{x}
+ expect(result).to eq(3)
+ end
+
+ it "does not break === with the monkey patch" do
+ expect(SampleForRbxInstanceEval === SampleForRbxInstanceEval.new).to be(true)
+ expect(BasicObject === SampleForRbxInstanceEval.new).to be(true)
+ expect(Bogus === SampleForRbxInstanceEval.new).to be(false)
+ end
+end
diff --git a/spec/bogus/bugs/rbx_jruby_stub_on_class_spec.rb b/spec/bogus/bugs/rbx_jruby_stub_on_class_spec.rb
new file mode 100644
index 0000000..8755d63
--- /dev/null
+++ b/spec/bogus/bugs/rbx_jruby_stub_on_class_spec.rb
@@ -0,0 +1,45 @@
+require 'spec_helper'
+
+class ExampleForRbxJRubyBug
+ def self.bar(argument)
+ argument
+ end
+
+ def self.foo(argument)
+ argument
+ end
+
+ def initialize(*args)
+ args
+ end
+end
+
+describe ExampleForRbxJRubyBug do
+ before do
+ extend Bogus::MockingDSL
+ end
+
+ context '.bar' do
+ specify 'stubbing class twice in example' do
+ stub(ExampleForRbxJRubyBug).bar('same_argument')
+ stub(ExampleForRbxJRubyBug).bar('same_argument')
+ end
+ end
+
+ context '.foo' do
+ specify 'stubbing class once in example' do
+ stub(ExampleForRbxJRubyBug).foo('same_argument')
+ end
+
+ specify 'stubbing class once in another example' do
+ stub(ExampleForRbxJRubyBug).foo('same_argument')
+ end
+ end
+
+ context '.new' do
+ before { stub(ExampleForRbxJRubyBug).new(any_args) }
+
+ specify { ExampleForRbxJRubyBug.new(1, 2, 3) }
+ specify { ExampleForRbxJRubyBug.new(1, 2, 3) }
+ end
+end
diff --git a/spec/bogus/contracts/adds_contract_verification_spec.rb b/spec/bogus/contracts/adds_contract_verification_spec.rb
index 807b423..7944ce2 100644
--- a/spec/bogus/contracts/adds_contract_verification_spec.rb
+++ b/spec/bogus/contracts/adds_contract_verification_spec.rb
@@ -37,7 +37,7 @@ describe Bogus::AddsContractVerification do
it "verifies the contract in after_suite" do
syntax.run_after_suite
- expect(verifies_contracts).to have_received.verify(:some_fake)
+ expect(verifies_contracts).to have_received(:verify).with(:some_fake)
end
end
@@ -49,17 +49,17 @@ describe Bogus::AddsContractVerification do
let(:overwritten_class) { :the_overwritten_class }
- let(:adds_recording) { stub }
- let(:verifies_contracts) { stub }
- let(:converts_name_to_class) { stub }
+ let(:adds_recording) { double }
+ let(:verifies_contracts) { double }
+ let(:converts_name_to_class) { double }
let(:syntax) { FakeSyntax.new(described_class) }
let(:adds_contract_verification) { isolate(Bogus::AddsContractVerification) }
before do
- stub(adds_recording).add { overwritten_class }
- stub(verifies_contracts).verify
- stub(converts_name_to_class).convert { ClassGuessedFromFakeName }
+ allow(adds_recording).to receive(:add) { overwritten_class }
+ allow(verifies_contracts).to receive(:verify)
+ allow(converts_name_to_class).to receive(:convert) { ClassGuessedFromFakeName }
end
context "with described_class" do
@@ -87,7 +87,7 @@ describe Bogus::AddsContractVerification do
it "adds recording to described_class" do
syntax.run_before
- expect(adds_recording).to have_received.add(:some_fake, SomeClass)
+ expect(adds_recording).to have_received(:add).with(:some_fake, SomeClass)
end
end
@@ -119,7 +119,7 @@ describe Bogus::AddsContractVerification do
it "adds recording to custom class" do
syntax.run_before
- expect(adds_recording).to have_received.add(:some_fake, ClassToOverwrite)
+ expect(adds_recording).to have_received(:add).with(:some_fake, ClassToOverwrite)
end
end
@@ -148,7 +148,7 @@ describe Bogus::AddsContractVerification do
it "adds recording to class based on fake name" do
syntax.run_before
- expect(adds_recording).to have_received.add(:some_fake, ClassGuessedFromFakeName)
+ expect(adds_recording).to have_received(:add).with(:some_fake, ClassGuessedFromFakeName)
end
end
end
diff --git a/spec/bogus/contracts/adds_recording_spec.rb b/spec/bogus/contracts/adds_recording_spec.rb
index 9fb8303..c43777d 100644
--- a/spec/bogus/contracts/adds_recording_spec.rb
+++ b/spec/bogus/contracts/adds_recording_spec.rb
@@ -9,16 +9,16 @@ describe Bogus::AddsRecording do
end
end
- let(:create_proxy_class) { stub }
- let(:overwrites_classes) { stub }
- let(:overwritten_classes) { stub }
+ let(:create_proxy_class) { double }
+ let(:overwrites_classes) { double }
+ let(:overwritten_classes) { double }
let(:adds_recording) { isolate(Bogus::AddsRecording) }
before do
- stub(create_proxy_class).call { Object }
- stub(overwrites_classes).overwrite
- stub(overwritten_classes).add
+ allow(create_proxy_class).to receive(:call) { Object }
+ allow(overwrites_classes).to receive(:overwrite)
+ allow(overwritten_classes).to receive(:add)
end
before do
@@ -26,15 +26,15 @@ describe Bogus::AddsRecording do
end
it "creates the proxy" do
- expect(create_proxy_class).to have_received.call(:library, SampleModule::Library)
+ expect(create_proxy_class).to have_received(:call).with(:library, SampleModule::Library)
end
it "swaps the classes" do
- expect(overwrites_classes).to have_received.overwrite('SampleModule::Library', Object)
+ expect(overwrites_classes).to have_received(:overwrite).with('SampleModule::Library', Object)
end
it "records the overwritten class, so that it can be later restored" do
- expect(overwritten_classes).to have_received.add("SampleModule::Library", SampleModule::Library)
+ expect(overwritten_classes).to have_received(:add).with("SampleModule::Library", SampleModule::Library)
end
it "returns the proxy class" do
diff --git a/spec/bogus/contracts/interactions_repository_spec.rb b/spec/bogus/contracts/interactions_repository_spec.rb
index aa6478f..b22973f 100644
--- a/spec/bogus/contracts/interactions_repository_spec.rb
+++ b/spec/bogus/contracts/interactions_repository_spec.rb
@@ -10,43 +10,43 @@ describe Bogus::InteractionsRepository do
it "considers the interaction recorded if it was recorded previously" do
interactions_repository.record(:foo, :bar, 1, 2, 3)
- expect(recorded?(:foo, :bar, 1, 2, 3)).to be_true
+ expect(recorded?(:foo, :bar, 1, 2, 3)).to be(true)
end
it "considers the interaction recorded if it returned the same value as passed block" do
interactions_repository.record(:foo, :bar) { "a result" }
interaction = Bogus::Interaction.new(:bar, []) { "a result" }
- expect(interactions_repository.recorded?(:foo, interaction)).to be_true
+ expect(interactions_repository.recorded?(:foo, interaction)).to be(true)
end
it "does not consider any interactions recorded prior to any recordings" do
- expect(recorded?(:foo, :bar, 1)).to be_false
+ expect(recorded?(:foo, :bar, 1)).to be(false)
end
it "does not consider the interaction recorded with a different fake name" do
interactions_repository.record(:baz, :bar, 1)
- expect(recorded?(:foo, :bar, 1)).to be_false
+ expect(recorded?(:foo, :bar, 1)).to be(false)
end
it "does not consider the interaction recorded with a different method name" do
interactions_repository.record(:foo, :baz, 1)
- expect(recorded?(:foo, :bar, 1)).to be_false
+ expect(recorded?(:foo, :bar, 1)).to be(false)
end
it "does not consider the interaction recorded with different method arguments" do
interactions_repository.record(:foo, :bar, 1, 2)
- expect(recorded?(:foo, :bar, 1)).to be_false
+ expect(recorded?(:foo, :bar, 1)).to be(false)
end
it "returns a list of interactions for given fake" do
interactions_repository.record(:foo, :bar, 1, 2)
interactions = interactions_repository.for_fake(:foo)
- expect(interactions).to have(1).item
+ expect(interactions.size).to eq(1)
expect(interactions.first.method).to eq :bar
expect(interactions.first.args).to eq [1, 2]
end
@@ -54,36 +54,36 @@ describe Bogus::InteractionsRepository do
it "ignores arguments if the checked interaction has any_args" do
interactions_repository.record(:foo, :bar, 1)
- expect(recorded?(:foo, :bar, Bogus::AnyArgs)).to be_true
+ expect(recorded?(:foo, :bar, Bogus::AnyArgs)).to be(true)
end
it "takes method name into account when matching interaction with wildcard arguments" do
interactions_repository.record(:foo, :baz, 1)
- expect(recorded?(:foo, :bar, Bogus::AnyArgs)).to be_false
+ expect(recorded?(:foo, :bar, Bogus::AnyArgs)).to be(false)
end
it "ignores arguments if the recorded interaction was recorded with wildcard argument" do
interactions_repository.record(:foo, :bar, 1, 2)
- expect(recorded?(:foo, :bar, 1, Bogus::Anything)).to be_true
+ expect(recorded?(:foo, :bar, 1, Bogus::Anything)).to be(true)
end
it "takes other arguments into account when matching interactions with wildcards" do
interactions_repository.record(:foo, :bar, 1, 2)
- expect(recorded?(:foo, :bar, 2, Bogus::Anything)).to be_false
+ expect(recorded?(:foo, :bar, 2, Bogus::Anything)).to be(false)
end
it "ignores arguments if the checked interaction has any_args" do
interactions_repository.record(:foo, :bar, 1, 2)
- expect(recorded?(:foo, :bar, 1, Bogus::Anything)).to be_true
+ expect(recorded?(:foo, :bar, 1, Bogus::Anything)).to be(true)
end
it "takes method name into account when matching interaction with wildcard arguments" do
interactions_repository.record(:foo, :baz, 1, 2)
- expect(recorded?(:foo, :bar, 1, Bogus::Anything)).to be_false
+ expect(recorded?(:foo, :bar, 1, Bogus::Anything)).to be(false)
end
end
diff --git a/spec/bogus/contracts/records_double_interactions_spec.rb b/spec/bogus/contracts/records_double_interactions_spec.rb
index 5197fd5..d2409d6 100644
--- a/spec/bogus/contracts/records_double_interactions_spec.rb
+++ b/spec/bogus/contracts/records_double_interactions_spec.rb
@@ -1,25 +1,27 @@
require 'spec_helper'
describe Bogus::RecordsDoubleInteractions do
- let(:fake_registry) { stub }
- let(:doubled_interactions) { stub }
+ let(:fake_registry) { double }
+ let(:doubled_interactions) { double }
let(:object) { Object.new }
let(:records_double_interactions) { isolate(Bogus::RecordsDoubleInteractions) }
it "records the call in double interaction repository" do
- stub(fake_registry).name(object) { :object_name }
- stub(doubled_interactions).record
+ allow(fake_registry).to receive(:name).with(object) { :object_name }
+ allow(doubled_interactions).to receive(:record)
records_double_interactions.record(object, :method_name, [:foo, 1])
- expect(doubled_interactions).to have_received.record(:object_name, :method_name, :foo, 1)
+ expect(doubled_interactions).to have_received(:record).with(:object_name, :method_name, :foo, 1)
end
it "does not record the interaction if object is not a fake" do
- stub(fake_registry).name(object) { nil }
- dont_allow(doubled_interactions).record
+ allow(fake_registry).to receive(:name).with(object) { nil }
+ allow(doubled_interactions).to receive(:record)
records_double_interactions.record(object, :method_name, [:foo, 1])
+
+ expect(doubled_interactions).not_to have_received(:record)
end
end
diff --git a/spec/bogus/contracts/verifies_contracts_spec.rb b/spec/bogus/contracts/verifies_contracts_spec.rb
index 8a152cb..693a5b4 100644
--- a/spec/bogus/contracts/verifies_contracts_spec.rb
+++ b/spec/bogus/contracts/verifies_contracts_spec.rb
@@ -1,8 +1,8 @@
require 'spec_helper'
describe Bogus::VerifiesContracts do
- let(:real_interactions) { stub }
- let(:doubled_interactions) { stub }
+ let(:real_interactions) { double }
+ let(:doubled_interactions) { double }
let(:verifies_contracts) { isolate(Bogus::VerifiesContracts) }
let(:matched_interaction) { interaction("matched") }
@@ -12,12 +12,12 @@ describe Bogus::VerifiesContracts do
second_interaction = interaction("second")
other_interaction = interaction("other")
- stub(doubled_interactions).for_fake(:fake_name){[first_interaction, matched_interaction, second_interaction]}
- stub(real_interactions).for_fake(:fake_name){[matched_interaction, other_interaction]}
+ allow(doubled_interactions).to receive(:for_fake).with(:fake_name){[first_interaction, matched_interaction, second_interaction]}
+ allow(real_interactions).to receive(:for_fake).with(:fake_name){[matched_interaction, other_interaction]}
- stub(real_interactions).recorded?(:fake_name, first_interaction) { false }
- stub(real_interactions).recorded?(:fake_name, second_interaction) { false }
- stub(real_interactions).recorded?(:fake_name, matched_interaction) { true }
+ allow(real_interactions).to receive(:recorded?).with(:fake_name, first_interaction) { false }
+ allow(real_interactions).to receive(:recorded?).with(:fake_name, second_interaction) { false }
+ allow(real_interactions).to receive(:recorded?).with(:fake_name, matched_interaction) { true }
expect_verify_to_raise_error_with_interactions(:fake_name,
[first_interaction, second_interaction],
@@ -25,8 +25,8 @@ describe Bogus::VerifiesContracts do
end
it "passes with all calls matched" do
- stub(doubled_interactions).for_fake(:fake_name) { [matched_interaction] }
- stub(real_interactions).recorded?(:fake_name, matched_interaction) { true }
+ allow(doubled_interactions).to receive(:for_fake).with(:fake_name) { [matched_interaction] }
+ allow(real_interactions).to receive(:recorded?).with(:fake_name, matched_interaction) { true }
expect {
verifies_contracts.verify(:fake_name)
diff --git a/spec/bogus/fakes/copies_classes_spec.rb b/spec/bogus/fakes/copies_classes_spec.rb
index 023e9ab..71301f8 100644
--- a/spec/bogus/fakes/copies_classes_spec.rb
+++ b/spec/bogus/fakes/copies_classes_spec.rb
@@ -125,15 +125,15 @@ describe Bogus::CopiesClasses do
end
it "should override kind_of?" do
- expect(fake.kind_of?(SomeModule::SomeClass)).to be_true
+ expect(fake.kind_of?(SomeModule::SomeClass)).to be(true)
end
it "should override instance_of?" do
- expect(fake.instance_of?(SomeModule::SomeClass)).to be_true
+ expect(fake.instance_of?(SomeModule::SomeClass)).to be(true)
end
it "should override is_a?" do
- expect(fake.is_a?(SomeModule::SomeClass)).to be_true
+ expect(fake.is_a?(SomeModule::SomeClass)).to be(true)
end
it "should include class name in the output of fake's class #to_s" do
@@ -145,13 +145,13 @@ describe Bogus::CopiesClasses do
end
it 'should override ===' do
- expect(SomeModule::SomeClass === fake).to be_true
+ expect(SomeModule::SomeClass === fake).to be(true)
end
end
shared_examples_for 'spying' do
def should_record(method, *args)
- mock(subject).__record__(method, *args)
+ expect(subject).to receive(:__record__).with(method, *args)
subject.send(method, *args)
end
diff --git a/spec/bogus/fakes/creates_fakes_spec.rb b/spec/bogus/fakes/creates_fakes_spec.rb
index 993be88..0aff73e 100644
--- a/spec/bogus/fakes/creates_fakes_spec.rb
+++ b/spec/bogus/fakes/creates_fakes_spec.rb
@@ -1,11 +1,11 @@
require 'spec_helper'
describe Bogus::CreatesFakes do
- let(:fake_class) { stub }
- let(:fake_instance) { stub }
- let(:converts_name_to_class) { stub }
- let(:copies_classes) { stub }
- let(:makes_ducks) { stub }
+ let(:fake_class) { double }
+ let(:fake_instance) { double }
+ let(:converts_name_to_class) { double }
+ let(:copies_classes) { double }
+ let(:makes_ducks) { double }
let(:creates_fakes) { isolate(Bogus::CreatesFakes) }
module Foo
@@ -14,12 +14,12 @@ describe Bogus::CreatesFakes do
module Bar
end
- before { stub(fake_class).__create__{fake_instance} }
+ before { allow(fake_class).to receive(:__create__){fake_instance} }
context "without block" do
before do
- mock(converts_name_to_class).convert(:foo) { Foo }
- mock(copies_classes).copy(Foo) { fake_class }
+ expect(converts_name_to_class).to receive(:convert).with(:foo) { Foo }
+ expect(copies_classes).to receive(:copy).with(Foo) { fake_class }
end
it "creates a new instance of copied class by default" do
@@ -43,8 +43,8 @@ describe Bogus::CreatesFakes do
context "with block" do
before do
- stub(converts_name_to_class).convert
- mock(copies_classes).copy(Bar) { fake_class }
+ allow(converts_name_to_class).to receive(:convert)
+ expect(copies_classes).to receive(:copy).with(Bar) { fake_class }
end
it "uses the class provided" do
@@ -54,7 +54,7 @@ describe Bogus::CreatesFakes do
it "does not convert the class name" do
creates_fakes.create(:foo) { Bar}
- expect(copies_classes).to_not have_received.convert
+ expect(converts_name_to_class).not_to have_received(:convert)
end
end
@@ -63,8 +63,8 @@ describe Bogus::CreatesFakes do
context "with multiple classes" do
it "creates a duck type out of those classes and fakes it" do
- stub(makes_ducks).make(Foo, Bar) { FooBarDuck }
- stub(copies_classes).copy(FooBarDuck) { :the_fake }
+ allow(makes_ducks).to receive(:make).with(Foo, Bar) { FooBarDuck }
+ allow(copies_classes).to receive(:copy).with(FooBarDuck) { :the_fake }
fake = creates_fakes.create(:role, as: :class) { [Foo, Bar] }
diff --git a/spec/bogus/fakes/creates_fakes_with_stubbed_methods_spec.rb b/spec/bogus/fakes/creates_fakes_with_stubbed_methods_spec.rb
index 8d29c90..0e41228 100644
--- a/spec/bogus/fakes/creates_fakes_with_stubbed_methods_spec.rb
+++ b/spec/bogus/fakes/creates_fakes_with_stubbed_methods_spec.rb
@@ -3,15 +3,15 @@ require 'spec_helper'
module Bogus
describe CreatesFakesWithStubbedMethods do
let(:creates_fakes) { FakeCreatorOfFakes.new }
- let(:fake_configuration) { stub }
- let(:responds_to_everything) { stub }
- let(:multi_stubber) { stub }
+ let(:fake_configuration) { double }
+ let(:responds_to_everything) { double }
+ let(:multi_stubber) { double }
let(:creates_anonymous_stubs) { isolate(CreatesFakesWithStubbedMethods) }
before do
- stub(fake_configuration).include? { false }
- stub(multi_stubber).stub_all { :stubbed_object }
+ allow(fake_configuration).to receive(:include?) { false }
+ allow(multi_stubber).to receive(:stub_all) { :stubbed_object }
end
context "given symbol as first parameter" do
@@ -26,7 +26,7 @@ module Bogus
end
it "stubs all the given methods" do
- expect(multi_stubber).to have_received.stub_all(fake, bar: 1)
+ expect(multi_stubber).to have_received(:stub_all).with(fake, bar: 1)
end
end
@@ -40,7 +40,7 @@ module Bogus
end
it "stubs all the given methods" do
- expect(multi_stubber).to have_received.stub_all(responds_to_everything, bar: 1)
+ expect(multi_stubber).to have_received(:stub_all).with(responds_to_everything, bar: 1)
end
end
@@ -56,7 +56,7 @@ module Bogus
end
it "stubs all the given methods" do
- expect(multi_stubber).to have_received.stub_all(fake, {})
+ expect(multi_stubber).to have_received(:stub_all).with(fake, {})
end
end
@@ -70,7 +70,7 @@ module Bogus
end
it "stubs all the given methods" do
- expect(multi_stubber).to have_received.stub_all(responds_to_everything, {})
+ expect(multi_stubber).to have_received(:stub_all).with(responds_to_everything, {})
end
end
@@ -78,8 +78,8 @@ module Bogus
let(:fake) { [:foo, {as: :class}, "SomeClass"] }
before do
- stub(fake_configuration).include?(:foo) { true }
- stub(fake_configuration).get(:foo) { FakeDefinition.new(opts: {as: :class},
+ allow(fake_configuration).to receive(:include?).with(:foo) { true }
+ allow(fake_configuration).to receive(:get).with(:foo) { FakeDefinition.new(opts: {as: :class},
stubs: {xyz: "abc"},
class_block: proc{"SomeClass"}) }
@@ -89,12 +89,12 @@ module Bogus
it "uses the configuration to create fake" do
expect(creates_fakes.fakes).to eq [fake]
- expect(fake_configuration).to have_received.include?(:foo)
- expect(fake_configuration).to have_received.get(:foo)
+ expect(fake_configuration).to have_received(:include?).with(:foo)
+ expect(fake_configuration).to have_received(:get).with(:foo)
end
it "stubs the methods defined in configuration" do
- expect(multi_stubber).to have_received.stub_all(fake, xyz: "abc")
+ expect(multi_stubber).to have_received(:stub_all).with(fake, xyz: "abc")
end
end
@@ -102,10 +102,12 @@ module Bogus
let(:fake) { [:foo, {as: :instance}, "SomeOtherClass"] }
before do
- stub(fake_configuration).include?(:foo) { true }
- stub(fake_configuration).get(:foo) { FakeDefinition.new(opts: {as: :class},
- stubs: {a: "b", b: "c"},
- class_block: proc{"SomeClass"}) }
+ allow(fake_configuration).to receive(:include?).with(:foo) { true }
+ allow(fake_configuration).to receive(:get).with(:foo) {
+ FakeDefinition.new(opts: {as: :class},
+ stubs: {a: "b", b: "c"},
+ class_block: proc{"SomeClass"})
+ }
creates_anonymous_stubs.create(:foo, as: :instance, b: "d", c: "e") { "SomeOtherClass" }
end
@@ -115,7 +117,7 @@ module Bogus
end
it "overrides the stubbed methods" do
- expect(multi_stubber).to have_received.stub_all(fake, a: "b", b: "d", c: "e")
+ expect(multi_stubber).to have_received(:stub_all).with(fake, a: "b", b: "d", c: "e")
end
end
end
diff --git a/spec/bogus/fakes/fake_ar_attributes_spec.rb b/spec/bogus/fakes/fake_ar_attributes_spec.rb
index d3c2e0a..be7dbbf 100644
--- a/spec/bogus/fakes/fake_ar_attributes_spec.rb
+++ b/spec/bogus/fakes/fake_ar_attributes_spec.rb
@@ -19,7 +19,9 @@ describe "Stubbing ActiveRecord::Base subclasses" do
end
end
- include Bogus::MockingDSL
+ before do
+ extend Bogus::MockingDSL
+ end
before do
Bogus.configure do |c|
diff --git a/spec/bogus/fakes/fake_configuration_spec.rb b/spec/bogus/fakes/fake_configuration_spec.rb
index 846f4dc..17fa8a1 100644
--- a/spec/bogus/fakes/fake_configuration_spec.rb
+++ b/spec/bogus/fakes/fake_configuration_spec.rb
@@ -4,7 +4,7 @@ describe Bogus::FakeConfiguration do
let(:config) { Bogus::FakeConfiguration.new }
it "does not contain not configured fakes" do
- expect(config.include?(:foo)).to be_false
+ expect(config.include?(:foo)).to be(false)
end
def class_block(name)
@@ -26,8 +26,8 @@ describe Bogus::FakeConfiguration do
end
end
- expect(config.include?(:foo)).to be_true
- expect(config.include?(:bar)).to be_false
+ expect(config.include?(:foo)).to be(true)
+ expect(config.include?(:bar)).to be(false)
end
it "returns the configuration for a fake" do
diff --git a/spec/bogus/fakes/fakes_classes_spec.rb b/spec/bogus/fakes/fakes_classes_spec.rb
index b3db7c2..a78d96f 100644
--- a/spec/bogus/fakes/fakes_classes_spec.rb
+++ b/spec/bogus/fakes/fakes_classes_spec.rb
@@ -2,8 +2,8 @@ require 'spec_helper'
describe Bogus::FakesClasses do
let(:creates_fakes_with_stubbed_methods) { FakeCreatorOfFakes.new }
- let(:overwrites_classes) { stub }
- let(:overwritten_classes) { stub }
+ let(:overwrites_classes) { double }
+ let(:overwritten_classes) { double }
let(:fakes_classes) { isolate(Bogus::FakesClasses) }
@@ -13,8 +13,8 @@ describe Bogus::FakesClasses do
end
before do
- stub(overwrites_classes).overwrite
- stub(overwritten_classes).add
+ allow(overwrites_classes).to receive(:overwrite)
+ allow(overwritten_classes).to receive(:add)
end
it "creates a fake named after the class" do
@@ -29,13 +29,13 @@ describe Bogus::FakesClasses do
fakes_classes.fake(Samples::WillBeOverwritten)
- expect(overwrites_classes).to have_received.overwrite("Samples::WillBeOverwritten", fake)
+ expect(overwrites_classes).to have_received(:overwrite).with("Samples::WillBeOverwritten", fake)
end
it "stores the overwritten class so that it can be replaced back later" do
fakes_classes.fake(Samples::WillBeOverwritten)
- expect(overwritten_classes).to have_received.add("Samples::WillBeOverwritten", Samples::WillBeOverwritten)
+ expect(overwritten_classes).to have_received(:add).with("Samples::WillBeOverwritten", Samples::WillBeOverwritten)
end
it "uses the passed fake name if provided" do
diff --git a/spec/bogus/fakes/faking_factories_spec.rb b/spec/bogus/fakes/faking_factories_spec.rb
index 358bdef..5e40173 100644
--- a/spec/bogus/fakes/faking_factories_spec.rb
+++ b/spec/bogus/fakes/faking_factories_spec.rb
@@ -1,7 +1,9 @@
require 'spec_helper'
describe "Faking Factories" do
- include Bogus::MockingDSL
+ before do
+ extend Bogus::MockingDSL
+ end
class ExampleFactory
def initialize(model_class)
diff --git a/spec/bogus/fakes/frozen_fakes_spec.rb b/spec/bogus/fakes/frozen_fakes_spec.rb
index 85ab853..da8f2d9 100644
--- a/spec/bogus/fakes/frozen_fakes_spec.rb
+++ b/spec/bogus/fakes/frozen_fakes_spec.rb
@@ -1,7 +1,9 @@
require "spec_helper"
describe "Frozen Fakes" do
- include Bogus::MockingDSL
+ before do
+ extend Bogus::MockingDSL
+ end
class ExampleForFreezing
def foo(x)
diff --git a/spec/bogus/fakes/registers_created_fakes_spec.rb b/spec/bogus/fakes/registers_created_fakes_spec.rb
index ea94e86..8252b36 100644
--- a/spec/bogus/fakes/registers_created_fakes_spec.rb
+++ b/spec/bogus/fakes/registers_created_fakes_spec.rb
@@ -1,28 +1,28 @@
require 'spec_helper'
describe Bogus::RegistersCreatedFakes do
- let(:fake_registry) { stub }
- let(:creates_fakes) { stub }
- let(:double_tracker) { stub }
+ let(:fake_registry) { double }
+ let(:creates_fakes) { double }
+ let(:double_tracker) { double }
let(:registers_created_fakes) { isolate(Bogus::RegistersCreatedFakes) }
before do
- stub(fake_registry).store
- stub(creates_fakes).create { :the_fake }
- stub(double_tracker).track(:the_fake)
+ allow(fake_registry).to receive(:store)
+ allow(creates_fakes).to receive(:create) { :the_fake }
+ allow(double_tracker).to receive(:track).with(:the_fake)
end
it "registers the fakes created by creates_fakes" do
registers_created_fakes.create(:foo, as: :instance) { Object }
- expect(fake_registry).to have_received.store(:foo, :the_fake)
+ expect(fake_registry).to have_received(:store).with(:foo, :the_fake)
end
it "tracks the created fakes for purposes of mock expectations" do
registers_created_fakes.create(:foo, as: :instance) { Object }
- expect(double_tracker).to have_received.track(:the_fake)
+ expect(double_tracker).to have_received(:track).with(:the_fake)
end
it "returns the created fake" do
diff --git a/spec/bogus/fakes/resets_overwritten_classes_spec.rb b/spec/bogus/fakes/resets_overwritten_classes_spec.rb
index 08da903..e712c6c 100644
--- a/spec/bogus/fakes/resets_overwritten_classes_spec.rb
+++ b/spec/bogus/fakes/resets_overwritten_classes_spec.rb
@@ -2,25 +2,25 @@ require 'spec_helper'
describe Bogus::ResetsOverwrittenClasses do
let(:classes) { [['Foo', :foo], ['Bar', :bar]] }
- let(:overwritten_classes) { stub }
- let(:overwrites_classes) { stub }
+ let(:overwritten_classes) { double }
+ let(:overwrites_classes) { double }
let(:resets_overwritten_classes) { isolate(Bogus::ResetsOverwrittenClasses) }
before do
- stub(overwritten_classes).classes { classes }
- stub(overwritten_classes).clear
- stub(overwrites_classes).overwrite
+ allow(overwritten_classes).to receive(:classes) { classes }
+ allow(overwritten_classes).to receive(:clear)
+ allow(overwrites_classes).to receive(:overwrite)
resets_overwritten_classes.reset
end
it "overwrites back all of the overwritten classes" do
- expect(overwrites_classes).to have_received.overwrite('Foo', :foo)
- expect(overwrites_classes).to have_received.overwrite('Bar', :bar)
+ expect(overwrites_classes).to have_received(:overwrite).with('Foo', :foo)
+ expect(overwrites_classes).to have_received(:overwrite).with('Bar', :bar)
end
it "clears the overwritten classes" do
- expect(overwritten_classes).to have_received.clear
+ expect(overwritten_classes).to have_received(:clear)
end
end
diff --git a/spec/bogus/fakes/stubbing_new_method_on_fake_class_spec.rb b/spec/bogus/fakes/stubbing_new_method_on_fake_class_spec.rb
index 893cd69..4ede840 100644
--- a/spec/bogus/fakes/stubbing_new_method_on_fake_class_spec.rb
+++ b/spec/bogus/fakes/stubbing_new_method_on_fake_class_spec.rb
@@ -4,7 +4,9 @@ describe "Stubbing .new on fake class" do
class ExampleForStubbingNew
end
- include Bogus::MockingDSL
+ before do
+ extend Bogus::MockingDSL
+ end
it "allows stubbing new on a class" do
fake_class = fake(ExampleForStubbingNew, as: :class)
diff --git a/spec/bogus/mocking_dsl_spec.rb b/spec/bogus/mocking_dsl_spec.rb
index 8c61210..e05cc98 100644
--- a/spec/bogus/mocking_dsl_spec.rb
+++ b/spec/bogus/mocking_dsl_spec.rb
@@ -239,7 +239,9 @@ describe Bogus::MockingDSL do
end
describe "#fake" do
- include Bogus::MockingDSL
+ before do
+ extend Bogus::MockingDSL
+ end
it "creates objects that can be stubbed" do
greeter = fake
diff --git a/spec/bogus/rspec/syntax_spec.rb b/spec/bogus/rspec/syntax_spec.rb
new file mode 100644
index 0000000..a82dbbe
--- /dev/null
+++ b/spec/bogus/rspec/syntax_spec.rb
@@ -0,0 +1,16 @@
+require 'spec_helper'
+
+describe Bogus::RSpecSyntax do
+ context = self
+ let(:syntax) { Bogus::RSpecSyntax.new(context) }
+
+ it "gets the described class" do
+ expect(syntax.described_class).to eq(Bogus::RSpecSyntax)
+ end
+
+ it "can set the described class" do
+ syntax.described_class = Object
+
+ expect(described_class).to eq(Object)
+ end
+end
diff --git a/spec/bogus/ruby_2_1_support_spec.rb b/spec/bogus/ruby_2_1_support_spec.rb
index d684f67..9ede0db 100644
--- a/spec/bogus/ruby_2_1_support_spec.rb
+++ b/spec/bogus/ruby_2_1_support_spec.rb
@@ -1,13 +1,15 @@
require 'spec_helper'
-if RUBY_VERSION >= '2.1'
+if RubyFeatures.required_keyword_arguments?
describe "Ruby 2.1 required keyword arguments" do
class ExampleForRequiredKeywordArgs
eval "def foo(x:); end"
eval "def bar(x:, **rest); end"
end
- include Bogus::MockingDSL
+ before do
+ extend Bogus::MockingDSL
+ end
context "with regular objects" do
subject { ExampleForRequiredKeywordArgs.new }
diff --git a/spec/bogus/ruby_2_support_spec.rb b/spec/bogus/ruby_2_support_spec.rb
index 23762cf..c461da9 100644
--- a/spec/bogus/ruby_2_support_spec.rb
+++ b/spec/bogus/ruby_2_support_spec.rb
@@ -1,13 +1,15 @@
require 'spec_helper'
-if RUBY_VERSION >= '2.0'
+if RubyFeatures.keyword_arguments?
describe "Ruby 2.0 keyword arguments" do
class ExampleForKeywordArgs
eval "def foo(x: 1); end"
eval "def bar(x: 1, **rest); end"
end
- include Bogus::MockingDSL
+ before do
+ extend Bogus::MockingDSL
+ end
context "with regular objects" do
subject { ExampleForKeywordArgs.new }
diff --git a/spec/bogus/stubbing/double_spec.rb b/spec/bogus/stubbing/double_spec.rb
index 7934c0a..fb3f8c9 100644
--- a/spec/bogus/stubbing/double_spec.rb
+++ b/spec/bogus/stubbing/double_spec.rb
@@ -4,59 +4,59 @@ module Bogus
describe Double do
shared_examples_for "double behavior" do
it "tracks existence of test doubles" do
- mock(double_tracker).track(object)
+ expect(double_tracker).to receive(:track).with(object)
- double.stub.foo("a", "b") { "the result" }
+ double_instance.stub.foo("a", "b") { "the result" }
end
it "does not track existence of the double if verify fails" do
- stub(verifies_stub_definition).verify!(object, :foo, ["a", "b"]) { raise NameError }
+ allow(verifies_stub_definition).to receive(:verify!).with(object, :foo, ["a", "b"]) { raise NameError }
expect {
- double.stub.foo("a", "b") { "the result" }
+ double_instance.stub.foo("a", "b") { "the result" }
}.to raise_error
- expect(double_tracker).not_to have_received.track(object)
+ expect(double_tracker).not_to have_received(:track).with(object)
end
it "verifies stub definition" do
- mock(verifies_stub_definition).verify!(object, :foo, ["a", "b"])
+ expect(verifies_stub_definition).to receive(:verify!).with(object, :foo, ["a", "b"])
- double.stub.foo("a", "b") { "the result" }
+ double_instance.stub.foo("a", "b") { "the result" }
end
it "stubs shadow methods" do
object.extend RecordInteractions
- mock(object.__shadow__).stubs(:foo, "a", "b")
+ expect(object.__shadow__).to receive(:stubs).with(:foo, "a", "b")
- double.stub.foo("a", "b") { "the result" }
+ double_instance.stub.foo("a", "b") { "the result" }
end
it "mocks shadow methods" do
object.extend RecordInteractions
- mock(object.__shadow__).mocks(:foo, "a", "b")
+ expect(object.__shadow__).to receive(:mocks).with(:foo, "a", "b")
- double.mock.foo("a", "b") { "the result" }
+ double_instance.mock.foo("a", "b") { "the result" }
end
it "adds method overwriting" do
- double.stub.foo("a", "b") { "the result" }
+ double_instance.stub.foo("a", "b") { "the result" }
expect(overwrites_methods.overwrites).to eq([[object, :foo]])
end
it "records double interactions" do
- mock(records_double_interactions).record(object, :foo, ["a", "b"])
+ expect(records_double_interactions).to receive(:record).with(object, :foo, ["a", "b"])
- double.stub.foo("a", "b") { "the result" }
+ double_instance.stub.foo("a", "b") { "the result" }
end
end
- let(:double_tracker) { stub(track: nil) }
- let(:verifies_stub_definition) { stub(verify!: nil) }
- let(:records_double_interactions) { stub(record: nil) }
+ let(:double_tracker) { double(:double_tracker, track: nil) }
+ let(:verifies_stub_definition) { double(:verifies_stub_definition, verify!: nil) }
+ let(:records_double_interactions) { double(:records_double_interactions, record: nil) }
let(:overwrites_methods) { FakeMethodOverwriter.new }
- let(:double) { isolate(Double) }
+ let(:double_instance) { isolate(Double) }
context "with regular objects" do
let(:object) { Samples::Foo.new }
diff --git a/spec/bogus/stubbing/have_received_matcher_spec.rb b/spec/bogus/stubbing/have_received_matcher_spec.rb
index 213db80..190b0b6 100644
--- a/spec/bogus/stubbing/have_received_matcher_spec.rb
+++ b/spec/bogus/stubbing/have_received_matcher_spec.rb
@@ -1,10 +1,9 @@
require 'spec_helper'
describe Bogus::HaveReceivedMatcher do
- let(:verifies_stub_definition) { stub(verify!: nil) }
- let(:records_double_interactions) { stub(record: nil) }
+ let(:verifies_stub_definition) { double(:verifies_stub_definition, verify!: nil) }
+ let(:records_double_interactions) { double(:records_double_interactions, record: nil) }
let(:have_received_matcher) { isolate(Bogus::HaveReceivedMatcher) }
- let(:have_received) { have_received_matcher.method_call }
let(:fake) { Samples::FooFake.new }
before do
@@ -13,33 +12,33 @@ describe Bogus::HaveReceivedMatcher do
shared_examples_for "have_received_matcher" do
it "matches when the spy has received the message" do
- expect(fake).to have_received(:foo, "a", "b")
+ expect(fake).to bogus_have_received(:foo, "a", "b")
end
it "does not match if the spy hasn't received the message" do
- expect(fake).not_to have_received(:foo, "a", "c")
+ expect(fake).not_to bogus_have_received(:foo, "a", "c")
end
it "verifies that the method call has the right signature" do
- mock(verifies_stub_definition).verify!(fake, :foo, ["a", "b"])
+ expect(verifies_stub_definition).to receive(:verify!).with(fake, :foo, ["a", "b"])
- have_received(:foo, "a", "b")
+ bogus_have_received(:foo, "a", "b")
have_received_matcher.matches?(fake)
end
it "records the interaction so that it can be checked by contract tests" do
- mock(records_double_interactions).record(fake, :foo, ["a", "b"])
+ expect(records_double_interactions).to receive(:record).with(fake, :foo, ["a", "b"])
- have_received(:foo, "a", "b")
+ bogus_have_received(:foo, "a", "b")
have_received_matcher.matches?(fake)
end
it "returns a readable error message for object with no shadow" do
- have_received(:upcase)
+ bogus_have_received(:upcase)
- expect(have_received_matcher.matches?("foo")).to be_false
+ expect(have_received_matcher.matches?("foo")).to be(false)
expect(have_received_matcher.failure_message_for_should).to eq(Bogus::HaveReceivedMatcher::NO_SHADOW)
expect(have_received_matcher.failure_message).to eq(Bogus::HaveReceivedMatcher::NO_SHADOW)
expect(have_received_matcher.failure_message_for_should_not).to eq(Bogus::HaveReceivedMatcher::NO_SHADOW)
@@ -47,7 +46,7 @@ describe Bogus::HaveReceivedMatcher do
end
it "returns a readable error message for fakes" do
- have_received(:foo, "a", "c")
+ bogus_have_received(:foo, "a", "c")
have_received_matcher.matches?(fake)
@@ -62,7 +61,7 @@ describe Bogus::HaveReceivedMatcher do
end
context "with method_missing builder" do
- def have_received(method, *args)
+ def bogus_have_received(method, *args)
have_received_matcher.build.__send__(method, *args)
end
@@ -70,7 +69,7 @@ describe Bogus::HaveReceivedMatcher do
end
context "with method call builder" do
- def have_received(*args)
+ def bogus_have_received(*args)
have_received_matcher.build(*args)
end
diff --git a/spec/bogus/stubbing/interaction_spec.rb b/spec/bogus/stubbing/interaction_spec.rb
index 27610e3..039424b 100644
--- a/spec/bogus/stubbing/interaction_spec.rb
+++ b/spec/bogus/stubbing/interaction_spec.rb
@@ -52,7 +52,7 @@ module Bogus
first = create_interaction(first_interaction)
second = create_interaction(second_interaction)
- expect(Interaction.same?(recorded: first, stubbed: second)).to be_true
+ expect(Interaction.same?(recorded: first, stubbed: second)).to be(true)
end
end
@@ -61,7 +61,7 @@ module Bogus
first = create_interaction(first_interaction)
second = create_interaction(second_interaction)
- expect(Interaction.same?(recorded: first, stubbed: second)).to be_false
+ expect(Interaction.same?(recorded: first, stubbed: second)).to be(false)
end
end
@@ -69,21 +69,21 @@ module Bogus
first = Interaction.new(:foo, [:bar]) { raise SomeError }
second = Interaction.new(:foo, [:bar]) { nil }
- expect(Interaction.same?(recorded: first, stubbed: second)).to be_false
+ expect(Interaction.same?(recorded: first, stubbed: second)).to be(false)
end
it "differs raised exceptions from ones just returned from the block" do
first = Interaction.new(:foo, [:bar]) { raise SomeError }
second = Interaction.new(:foo, [:bar]) { SomeError }
- expect(Interaction.same?(recorded: first, stubbed: second)).to be_false
+ expect(Interaction.same?(recorded: first, stubbed: second)).to be(false)
end
it "considers exceptions of the same type as equal" do
first = Interaction.new(:foo, [:bar]) { raise SomeError }
second = Interaction.new(:foo, [:bar]) { raise SomeError }
- expect(Interaction.same?(recorded: first, stubbed: second)).to be_true
+ expect(Interaction.same?(recorded: first, stubbed: second)).to be(true)
end
context 'when comparing arguments with custom #== implementations' do
@@ -97,14 +97,14 @@ module Bogus
first = Interaction.new(:with, [Dev.new(:psyho)])
second = Interaction.new(:with, [Dev.new(:psyho)])
- expect(Interaction.same?(recorded: first, stubbed: second)).to be_true
+ expect(Interaction.same?(recorded: first, stubbed: second)).to be(true)
end
it "considers two interactions != when the arguments are !=" do
first = Interaction.new(:with, [Dev.new(:wrozka)])
second = Interaction.new(:with, [Dev.new(:yundt)])
- expect(Interaction.same?(recorded: first, stubbed: second)).to be_false
+ expect(Interaction.same?(recorded: first, stubbed: second)).to be(false)
end
end
end
diff --git a/spec/bogus/stubbing/multi_stubber_spec.rb b/spec/bogus/stubbing/multi_stubber_spec.rb
index e40622a..005fa9c 100644
--- a/spec/bogus/stubbing/multi_stubber_spec.rb
+++ b/spec/bogus/stubbing/multi_stubber_spec.rb
@@ -1,22 +1,22 @@
require 'spec_helper'
describe Bogus::MultiStubber do
- let(:double) { FakeDouble.new }
- let(:create_double) { proc{ double } }
- let(:any_args) { Bogus::AnyArgs }
+ let(:fake_double) { FakeDouble.new }
+ let(:bogus_any_args) { Bogus::AnyArgs }
+ let(:create_double) { proc{ fake_double } }
let(:multi_stubber) { isolate(Bogus::MultiStubber) }
it "stubs all the given methods with any args returning the given value" do
multi_stubber.stub_all(Object.new, foo: 1, bar: 2)
- expect(double.stubbed).to eq([[:foo, [any_args], 1], [:bar, [any_args], 2]])
+ expect(fake_double.stubbed).to eq([[:foo, [bogus_any_args], 1], [:bar, [bogus_any_args], 2]])
end
it "uses passed procs as the return value block" do
multi_stubber.stub_all(Object.new, foo: proc{ 1 })
- expect(double.stubbed).to eq([[:foo, [any_args], 1]])
+ expect(fake_double.stubbed).to eq([[:foo, [bogus_any_args], 1]])
end
class FakeDouble
diff --git a/spec/bogus/stubbing/record_interactions_spec.rb b/spec/bogus/stubbing/record_interactions_spec.rb
index 2ca5640..0329cca 100644
--- a/spec/bogus/stubbing/record_interactions_spec.rb
+++ b/spec/bogus/stubbing/record_interactions_spec.rb
@@ -11,13 +11,13 @@ describe Bogus::RecordInteractions do
it "allows verifying that interactions happened" do
sample.__record__(:foo, 1, 2, 3)
- expect(sample.__shadow__.has_received(:foo, [1,2,3])).to be_true
+ expect(sample.__shadow__.has_received(:foo, [1,2,3])).to be(true)
end
it "allows verifying that interactions didn't happen" do
sample.__record__(:bar)
- expect(sample.__shadow__.has_received(:foo, [1,2,3])).to be_false
+ expect(sample.__shadow__.has_received(:foo, [1,2,3])).to be(false)
end
it "returns self from record by default" do
diff --git a/spec/bogus/stubbing/resets_stubbed_methods_spec.rb b/spec/bogus/stubbing/resets_stubbed_methods_spec.rb
index 3c3738f..5cf7d05 100644
--- a/spec/bogus/stubbing/resets_stubbed_methods_spec.rb
+++ b/spec/bogus/stubbing/resets_stubbed_methods_spec.rb
@@ -1,15 +1,15 @@
require 'spec_helper'
describe Bogus::ResetsStubbedMethods do
- let(:double_tracker) { stub }
- let(:overwrites_methods) { stub }
+ let(:double_tracker) { double }
+ let(:overwrites_methods) { double }
let(:resets_stubbed_methods) { isolate(Bogus::ResetsStubbedMethods) }
it "resets all stubbed objects back to previous implementation" do
- foo = stub
- stub(double_tracker).doubles { [foo] }
- mock(overwrites_methods).reset(foo)
+ foo = double
+ allow(double_tracker).to receive(:doubles) { [foo] }
+ expect(overwrites_methods).to receive(:reset).with(foo)
resets_stubbed_methods.reset_all_doubles
end
diff --git a/spec/bogus/stubbing/shadow_spec.rb b/spec/bogus/stubbing/shadow_spec.rb
index a6c7244..056bbe3 100644
--- a/spec/bogus/stubbing/shadow_spec.rb
+++ b/spec/bogus/stubbing/shadow_spec.rb
@@ -11,12 +11,12 @@ describe Bogus::Shadow do
end
it "returns the called methods" do
- expect(shadow.has_received(:foo, ["a", "b"])).to be_true
+ expect(shadow.has_received(:foo, ["a", "b"])).to be(true)
end
it "does not return true for interactions that did not happen" do
- expect(shadow.has_received(:foo, ["a", "c"])).to be_false
- expect(shadow.has_received(:bar, ["a", "c"])).to be_false
+ expect(shadow.has_received(:foo, ["a", "c"])).to be(false)
+ expect(shadow.has_received(:bar, ["a", "c"])).to be(false)
end
end
end
@@ -81,7 +81,7 @@ describe Bogus::Shadow do
it "allows spying on calls using any args" do
shadow.run(:foo, "a", "c")
- expect(shadow.has_received(:foo, [Bogus::AnyArgs])).to be_true
+ expect(shadow.has_received(:foo, [Bogus::AnyArgs])).to be(true)
end
end
@@ -103,7 +103,7 @@ describe Bogus::Shadow do
it "allows spying on calls using anything in args" do
shadow.run(:foo, "a", "b")
- expect(shadow.has_received(:foo, [Bogus::Anything, "b"])).to be_true
+ expect(shadow.has_received(:foo, [Bogus::Anything, "b"])).to be(true)
end
end
@@ -177,7 +177,7 @@ describe Bogus::Shadow do
it "contributes towards unsatisfied interactions" do
interactions = shadow.unsatisfied_interactions
- expect(interactions).to have(1).item
+ expect(interactions.size).to eq(1)
expect(interactions.first.method).to eq(:foo)
expect(interactions.first.args).to eq(["a", "b"])
end
diff --git a/spec/bogus/stubbing/stubbing_existing_methods_on_fakes_spec.rb b/spec/bogus/stubbing/stubbing_existing_methods_on_fakes_spec.rb
index 72248b9..90a685f 100644
--- a/spec/bogus/stubbing/stubbing_existing_methods_on_fakes_spec.rb
+++ b/spec/bogus/stubbing/stubbing_existing_methods_on_fakes_spec.rb
@@ -1,9 +1,9 @@
require 'spec_helper'
describe "Stubbing existing methods on fakes" do
- include Bogus::MockingDSL
before do
+ extend Bogus::MockingDSL
Bogus.clear
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 34255b3..b770334 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,14 +1,14 @@
require 'simplecov'
begin
require "coveralls"
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
+ SimpleCov::Formatter::HTMLFormatter,
+ Coveralls::SimpleCov::Formatter]
rescue LoadError
warn "warning: coveralls gem not found; skipping Coveralls"
+ SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
end
-SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
- SimpleCov::Formatter::HTMLFormatter,
- Coveralls::SimpleCov::Formatter]
-
SimpleCov.start do
add_filter "/spec/"
end
@@ -16,19 +16,12 @@ end
require 'bogus'
require 'dependor/rspec'
-require 'rr'
-
require_relative 'support/sample_fake'
require_relative 'support/fake_creator_of_fakes'
require_relative 'support/matchers'
require_relative 'support/shared_examples_for_keyword_arguments'
+require_relative 'support/ruby_features'
RSpec.configure do |config|
- config.color_enabled = true
- config.mock_framework = :rr
-end
-
-# this should not be necessary...
-def have_received(method = nil)
- RR::Adapters::Rspec::InvocationMatcher.new(method)
+ config.mock_with :rspec
end
diff --git a/spec/support/ruby_features.rb b/spec/support/ruby_features.rb
new file mode 100644
index 0000000..360b277
--- /dev/null
+++ b/spec/support/ruby_features.rb
@@ -0,0 +1,19 @@
+module RubyFeatures
+ module_function
+
+ def keyword_arguments?
+ ruby?('2.0') && !rbx?
+ end
+
+ def required_keyword_arguments?
+ ruby?('2.1') && keyword_arguments?
+ end
+
+ def ruby?(version)
+ RUBY_VERSION >= version
+ end
+
+ def rbx?
+ RUBY_ENGINE == 'rbx'
+ end
+end
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-bogus.git
More information about the Pkg-ruby-extras-commits
mailing list