Permalink
Browse files

Convert specs to the latest RSpec syntax with Transpec

This conversion is done by Transpec 1.4.0 with the following command:
    transpec -m -s --keep should,deprecated

* 79 conversions
    from: obj.should_receive(:message)
      to: expect(obj).to receive(:message)

* 10 conversions
    from: obj.should_not_receive(:message)
      to: expect(obj).not_to receive(:message)

* 8 conversions
    from: obj.stub(:message)
      to: allow(obj).to receive(:message)

* 3 conversions
    from: obj.stub(:message => value)
      to: allow(obj).to receive_messages(:message => value)
  • Loading branch information...
myronmarston committed Nov 25, 2013
1 parent 3cb8e96 commit f2121650e10464b8cb004e66d03bc77bc7746c6b
@@ -8,7 +8,7 @@ module Expectations
let(:differ) { RSpec::Expectations::DiffPresenter.new }
context "without --color" do
- before { RSpec::Matchers.configuration.stub(:color? => false) }
+ before { allow(RSpec::Matchers.configuration).to receive_messages(:color? => false) }
describe '#diff_as_string' do
subject { differ.diff_as_string(@actual, @expected) }
@@ -215,7 +215,7 @@ def inspect
end
context "with --color" do
- before { RSpec::Matchers.configuration.stub(:color? => true) }
+ before { allow(RSpec::Matchers.configuration).to receive_messages(:color? => true) }
it "outputs colored diffs" do
expected = "foo bar baz"
@@ -4,18 +4,18 @@
before(:each) do
@target = "target"
@matcher = double("matcher")
- @matcher.stub(:matches?).and_return(true)
- @matcher.stub(:failure_message_for_should)
+ allow(@matcher).to receive(:matches?).and_return(true)
+ allow(@matcher).to receive(:failure_message_for_should)
end
it "accepts and interacts with a matcher" do
- @matcher.should_receive(:matches?).with(@target).and_return(true)
+ expect(@matcher).to receive(:matches?).with(@target).and_return(true)
expect(@target).to @matcher
end
it "asks for a failure_message_for_should when matches? returns false" do
- @matcher.should_receive(:matches?).with(@target).and_return(false)
- @matcher.should_receive(:failure_message_for_should).and_return("the failure message")
+ expect(@matcher).to receive(:matches?).with(@target).and_return(false)
+ expect(@matcher).to receive(:failure_message_for_should).and_return("the failure message")
expect {
expect(@target).to @matcher
}.to fail_with("the failure message")
@@ -51,15 +51,15 @@ def method_missing(name, *args)
end
it "accepts and interacts with a matcher" do
- @matcher.should_receive(:matches?).with(@target).and_return(false)
- @matcher.stub(:failure_message_for_should_not)
+ expect(@matcher).to receive(:matches?).with(@target).and_return(false)
+ allow(@matcher).to receive(:failure_message_for_should_not)
expect(@target).not_to @matcher
end
it "asks for a failure_message_for_should_not when matches? returns true" do
- @matcher.should_receive(:matches?).with(@target).and_return(true)
- @matcher.should_receive(:failure_message_for_should_not).and_return("the failure message for should not")
+ expect(@matcher).to receive(:matches?).with(@target).and_return(true)
+ expect(@matcher).to receive(:failure_message_for_should_not).and_return("the failure message for should not")
expect {
expect(@target).not_to @matcher
}.to fail_with("the failure message for should not")
@@ -3,7 +3,7 @@
describe RSpec::Expectations, "#fail_with with diff of arrays" do
- before { RSpec::Matchers.configuration.stub(:color? => false) }
+ before { allow(RSpec::Matchers.configuration).to receive_messages(:color? => false) }
it "splits items with newlines" do
expected_diff = "\nDiff:\n@@ -1 +1,3 @@\n+a\\nb\n+c\\nd\n"
@@ -24,11 +24,11 @@
let(:differ) { double("differ") }
before(:each) do
- RSpec::Expectations.stub(:differ) { differ }
+ allow(RSpec::Expectations).to receive(:differ) { differ }
end
it "calls differ if expected/actual are not strings (or numbers or procs)" do
- differ.should_receive(:diff_as_object).and_return("diff")
+ expect(differ).to receive(:diff_as_object).and_return("diff")
expect {
RSpec::Expectations.fail_with "the message", Object.new, Object.new
}.to fail_with("the message\nDiff:diff")
@@ -37,7 +37,7 @@
context "with two strings" do
context "and actual is multiline" do
it "calls differ" do
- differ.should_receive(:diff_as_string).and_return("diff")
+ expect(differ).to receive(:diff_as_string).and_return("diff")
expect {
RSpec::Expectations.fail_with "the message", "expected\nthis", "actual"
}.to fail_with("the message\nDiff:diff")
@@ -46,7 +46,7 @@
context "and expected is multiline" do
it "calls differ" do
- differ.should_receive(:diff_as_string).and_return("diff")
+ expect(differ).to receive(:diff_as_string).and_return("diff")
expect {
RSpec::Expectations.fail_with "the message", "expected", "actual\nthat"
}.to fail_with("the message\nDiff:diff")
@@ -55,7 +55,7 @@
context "and both are single line strings" do
it "does not call differ" do
- differ.should_not_receive(:diff_as_string)
+ expect(differ).not_to receive(:diff_as_string)
expect {
RSpec::Expectations.fail_with("the message", "expected", "actual")
}.to fail_with("the message")
@@ -64,7 +64,7 @@
context "and they are UTF-16LE encoded", :if => String.method_defined?(:encode) do
it 'does not diff when they are not multiline' do
- differ.should_not_receive(:diff_as_string)
+ expect(differ).not_to receive(:diff_as_string)
str_1 = "This is a pile of poo: 💩".encode("UTF-16LE")
str_2 = "This is a pile of poo: 💩".encode("UTF-16LE")
@@ -75,7 +75,7 @@
end
it 'diffs when they are multiline' do
- differ.should_receive(:diff_as_string).and_return("diff")
+ expect(differ).to receive(:diff_as_string).and_return("diff")
str_1 = "This is a pile of poo:\n💩".encode("UTF-16LE")
str_2 = "This is a pile of poo:\n💩".encode("UTF-16LE")
@@ -51,22 +51,22 @@ module Expectations
it "asks the matcher if it matches" do
matcher = double("matcher")
actual = Object.new
- matcher.should_receive(:matches?).with(actual).and_return(true)
+ expect(matcher).to receive(:matches?).with(actual).and_return(true)
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)
end
it "returns the match value" do
matcher = double("matcher")
actual = Object.new
- matcher.should_receive(:matches?).with(actual).and_return(:this_value)
+ expect(matcher).to receive(:matches?).with(actual).and_return(:this_value)
expect(RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)).to eq :this_value
end
it "calls failure_message_for_should if the matcher implements it" do
matcher = double("matcher", :failure_message_for_should => "message", :matches? => false)
actual = Object.new
- ::RSpec::Expectations.should_receive(:fail_with).with("message")
+ expect(::RSpec::Expectations).to receive(:fail_with).with("message")
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)
end
@@ -81,7 +81,7 @@ module Expectations
)
actual = Object.new
- ::RSpec::Expectations.should_receive(:fail_with).with("message", 1, 2)
+ expect(::RSpec::Expectations).to receive(:fail_with).with("message", 1, 2)
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)
end
@@ -90,7 +90,7 @@ module Expectations
matcher = double("matcher", :failure_message => "message", :matches? => false)
actual = Object.new
- ::RSpec::Expectations.should_receive(:fail_with).with("message")
+ expect(::RSpec::Expectations).to receive(:fail_with).with("message")
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher)
@@ -100,7 +100,7 @@ module Expectations
matcher = double("matcher", :failure_message_for_should => "message", :matches? => false)
actual = Object.new
- ::RSpec::Expectations.should_receive(:fail_with).with("custom")
+ expect(::RSpec::Expectations).to receive(:fail_with).with("custom")
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher, "custom")
end
@@ -111,7 +111,7 @@ module Expectations
failure_message = double("failure message", :call => "custom")
- ::RSpec::Expectations.should_receive(:fail_with).with("custom")
+ expect(::RSpec::Expectations).to receive(:fail_with).with("custom")
RSpec::Expectations::PositiveExpectationHandler.handle_matcher(actual, matcher, failure_message)
end
@@ -123,23 +123,23 @@ module Expectations
it "asks the matcher if it doesn't match when the matcher responds to #does_not_match?" do
matcher = double("matcher", :does_not_match? => true, :negative_failure_message => nil)
actual = Object.new
- matcher.should_receive(:does_not_match?).with(actual).and_return(true)
+ expect(matcher).to receive(:does_not_match?).with(actual).and_return(true)
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
end
it "asks the matcher if it matches when the matcher doesn't respond to #does_not_match?" do
matcher = double("matcher")
actual = Object.new
- matcher.stub(:negative_failure_message)
- matcher.should_receive(:matches?).with(actual).and_return(false)
+ allow(matcher).to receive(:negative_failure_message)
+ expect(matcher).to receive(:matches?).with(actual).and_return(false)
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
end
it "returns the match value" do
matcher = double("matcher")
actual = Object.new
- matcher.should_receive(:matches?).with(actual).and_return(false)
- matcher.stub(:negative_failure_message).and_return("ignore")
+ expect(matcher).to receive(:matches?).with(actual).and_return(false)
+ allow(matcher).to receive(:negative_failure_message).and_return("ignore")
expect(RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)).to be_falsey
end
@@ -148,7 +148,7 @@ module Expectations
matcher = double("matcher", :failure_message_for_should_not => "message", :matches? => true)
actual = Object.new
- ::RSpec::Expectations.should_receive(:fail_with).with("message")
+ expect(::RSpec::Expectations).to receive(:fail_with).with("message")
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
@@ -158,7 +158,7 @@ module Expectations
matcher = double("matcher", :negative_failure_message => "message", :matches? => true)
actual = Object.new
- ::RSpec::Expectations.should_receive(:fail_with).with("message")
+ expect(::RSpec::Expectations).to receive(:fail_with).with("message")
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
@@ -175,7 +175,7 @@ module Expectations
)
actual = Object.new
- ::RSpec::Expectations.should_receive(:fail_with).with("message", 1, 2)
+ expect(::RSpec::Expectations).to receive(:fail_with).with("message", 1, 2)
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher)
end
@@ -184,7 +184,7 @@ module Expectations
matcher = double("matcher", :failure_message_for_should_not => "message", :matches? => true)
actual = Object.new
- ::RSpec::Expectations.should_receive(:fail_with).with("custom")
+ expect(::RSpec::Expectations).to receive(:fail_with).with("custom")
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher, "custom")
end
@@ -195,7 +195,7 @@ module Expectations
failure_message = double("failure message", :call => "custom")
- ::RSpec::Expectations.should_receive(:fail_with).with("custom")
+ expect(::RSpec::Expectations).to receive(:fail_with).with("custom")
RSpec::Expectations::NegativeExpectationHandler.handle_matcher(actual, matcher, failure_message)
end
@@ -20,54 +20,54 @@ module Expectations
describe "expect(...).to" do
it "prints a warning when the message object isn't a String" do
- warner.should_receive(:warn).with(/ignoring.*message/)
+ expect(warner).to receive(:warn).with(/ignoring.*message/)
expect(3).to eq(3), :not_a_string
end
it "doesn't print a warning when message is a String" do
- warner.should_not_receive(:warn)
+ expect(warner).not_to receive(:warn)
expect(3).to eq(3), "a string"
end
it "doesn't print a warning when message responds to to_str" do
- warner.should_not_receive(:warn)
+ expect(warner).not_to receive(:warn)
expect(3).to eq(3), string_like_object
end
it "prints a warning when the message object handles to_s but not to_str" do
- warner.should_receive(:warn).with(/ignoring.*message/)
+ expect(warner).to receive(:warn).with(/ignoring.*message/)
expect(3).to eq(3), insufficiently_string_like_object
end
it "doesn't print a warning when message responds to call" do
- warner.should_not_receive(:warn)
+ expect(warner).not_to receive(:warn)
expect(3).to eq(3), callable_object
end
end
describe "expect(...).not_to" do
it "prints a warning when the message object isn't a String" do
- warner.should_receive(:warn).with(/ignoring.*message/)
+ expect(warner).to receive(:warn).with(/ignoring.*message/)
expect(3).not_to eq(4), :not_a_string
end
it "doesn't print a warning when message is a String" do
- warner.should_not_receive(:warn)
+ expect(warner).not_to receive(:warn)
expect(3).not_to eq(4), "a string"
end
it "doesn't print a warning when message responds to to_str" do
- warner.should_not_receive(:warn)
+ expect(warner).not_to receive(:warn)
expect(3).not_to eq(4), string_like_object
end
it "prints a warning when the message object handles to_s but not to_str" do
- warner.should_receive(:warn).with(/ignoring.*message/)
+ expect(warner).to receive(:warn).with(/ignoring.*message/)
expect(3).not_to eq(4), insufficiently_string_like_object
end
it "doesn't print a warning when message responds to call" do
- warner.should_not_receive(:warn)
+ expect(warner).not_to receive(:warn)
expect(3).not_to eq(4), callable_object
end
end
Oops, something went wrong.

0 comments on commit f212165

Please sign in to comment.