summaryrefslogtreecommitdiff
path: root/spec/mspec/spec/runner/context_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/mspec/spec/runner/context_spec.rb')
-rw-r--r--spec/mspec/spec/runner/context_spec.rb342
1 files changed, 171 insertions, 171 deletions
diff --git a/spec/mspec/spec/runner/context_spec.rb b/spec/mspec/spec/runner/context_spec.rb
index c5aa691323..a864428aec 100644
--- a/spec/mspec/spec/runner/context_spec.rb
+++ b/spec/mspec/spec/runner/context_spec.rb
@@ -6,7 +6,7 @@ require 'mspec/mocks/mock'
require 'mspec/runner/context'
require 'mspec/runner/example'
-describe ContextState, "#describe" do
+RSpec.describe ContextState, "#describe" do
before :each do
@state = ContextState.new "C#m"
@proc = proc { ScratchPad.record :a }
@@ -15,63 +15,63 @@ describe ContextState, "#describe" do
it "evaluates the passed block" do
@state.describe(&@proc)
- ScratchPad.recorded.should == :a
+ expect(ScratchPad.recorded).to eq(:a)
end
it "evaluates the passed block via #protect" do
- @state.should_receive(:protect).with("C#m", @proc, false)
+ expect(@state).to receive(:protect).with("C#m", @proc, false)
@state.describe(&@proc)
end
it "registers #parent as the current MSpec ContextState" do
parent = ContextState.new ""
@state.parent = parent
- MSpec.should_receive(:register_current).with(parent)
+ expect(MSpec).to receive(:register_current).with(parent)
@state.describe { }
end
it "registers self with MSpec when #shared? is true" do
state = ContextState.new "something shared", :shared => true
- MSpec.should_receive(:register_shared).with(state)
+ expect(MSpec).to receive(:register_shared).with(state)
state.describe { }
end
end
-describe ContextState, "#shared?" do
+RSpec.describe ContextState, "#shared?" do
it "returns false when the ContextState is not shared" do
- ContextState.new("").shared?.should be_false
+ expect(ContextState.new("").shared?).to be_falsey
end
it "returns true when the ContextState is shared" do
- ContextState.new("", {:shared => true}).shared?.should be_true
+ expect(ContextState.new("", {:shared => true}).shared?).to be_truthy
end
end
-describe ContextState, "#to_s" do
+RSpec.describe ContextState, "#to_s" do
it "returns a description string for self when passed a Module" do
- ContextState.new(Object).to_s.should == "Object"
+ expect(ContextState.new(Object).to_s).to eq("Object")
end
it "returns a description string for self when passed a String" do
- ContextState.new("SomeClass").to_s.should == "SomeClass"
+ expect(ContextState.new("SomeClass").to_s).to eq("SomeClass")
end
end
-describe ContextState, "#description" do
+RSpec.describe ContextState, "#description" do
before :each do
@state = ContextState.new "when empty"
@parent = ContextState.new "Toplevel"
end
it "returns a composite description string from self and all parents" do
- @parent.description.should == "Toplevel"
- @state.description.should == "when empty"
+ expect(@parent.description).to eq("Toplevel")
+ expect(@state.description).to eq("when empty")
@state.parent = @parent
- @state.description.should == "Toplevel when empty"
+ expect(@state.description).to eq("Toplevel when empty")
end
end
-describe ContextState, "#it" do
+RSpec.describe ContextState, "#it" do
before :each do
@state = ContextState.new ""
@proc = lambda {|*| }
@@ -80,25 +80,25 @@ describe ContextState, "#it" do
end
it "creates an ExampleState instance for the block" do
- ExampleState.should_receive(:new).with(@state, "it", @proc).and_return(@ex)
+ expect(ExampleState).to receive(:new).with(@state, "it", @proc).and_return(@ex)
@state.describe(&@proc)
@state.it("it", &@proc)
end
it "calls registered :add actions" do
- ExampleState.should_receive(:new).with(@state, "it", @proc).and_return(@ex)
+ expect(ExampleState).to receive(:new).with(@state, "it", @proc).and_return(@ex)
add_action = double("add")
- add_action.should_receive(:add).with(@ex).and_return { ScratchPad.record :add }
+ expect(add_action).to receive(:add).with(@ex) { ScratchPad.record :add }
MSpec.register :add, add_action
@state.it("it", &@proc)
- ScratchPad.recorded.should == :add
+ expect(ScratchPad.recorded).to eq(:add)
MSpec.unregister :add, add_action
end
end
-describe ContextState, "#examples" do
+RSpec.describe ContextState, "#examples" do
before :each do
@state = ContextState.new ""
end
@@ -106,11 +106,11 @@ describe ContextState, "#examples" do
it "returns a list of all examples in this ContextState" do
@state.it("first") { }
@state.it("second") { }
- @state.examples.size.should == 2
+ expect(@state.examples.size).to eq(2)
end
end
-describe ContextState, "#before" do
+RSpec.describe ContextState, "#before" do
before :each do
@state = ContextState.new ""
@proc = lambda {|*| }
@@ -118,16 +118,16 @@ describe ContextState, "#before" do
it "records the block for :each" do
@state.before(:each, &@proc)
- @state.before(:each).should == [@proc]
+ expect(@state.before(:each)).to eq([@proc])
end
it "records the block for :all" do
@state.before(:all, &@proc)
- @state.before(:all).should == [@proc]
+ expect(@state.before(:all)).to eq([@proc])
end
end
-describe ContextState, "#after" do
+RSpec.describe ContextState, "#after" do
before :each do
@state = ContextState.new ""
@proc = lambda {|*| }
@@ -135,16 +135,16 @@ describe ContextState, "#after" do
it "records the block for :each" do
@state.after(:each, &@proc)
- @state.after(:each).should == [@proc]
+ expect(@state.after(:each)).to eq([@proc])
end
it "records the block for :all" do
@state.after(:all, &@proc)
- @state.after(:all).should == [@proc]
+ expect(@state.after(:all)).to eq([@proc])
end
end
-describe ContextState, "#pre" do
+RSpec.describe ContextState, "#pre" do
before :each do
@a = lambda {|*| }
@b = lambda {|*| }
@@ -161,17 +161,17 @@ describe ContextState, "#pre" do
it "returns before(:each) actions in the order they were defined" do
@state.before(:each, &@a)
@state.before(:each, &@b)
- @state.pre(:each).should == [@c, @a, @b]
+ expect(@state.pre(:each)).to eq([@c, @a, @b])
end
it "returns before(:all) actions in the order they were defined" do
@state.before(:all, &@a)
@state.before(:all, &@b)
- @state.pre(:all).should == [@c, @a, @b]
+ expect(@state.pre(:all)).to eq([@c, @a, @b])
end
end
-describe ContextState, "#post" do
+RSpec.describe ContextState, "#post" do
before :each do
@a = lambda {|*| }
@b = lambda {|*| }
@@ -188,17 +188,17 @@ describe ContextState, "#post" do
it "returns after(:each) actions in the reverse order they were defined" do
@state.after(:each, &@a)
@state.after(:each, &@b)
- @state.post(:each).should == [@b, @a, @c]
+ expect(@state.post(:each)).to eq([@b, @a, @c])
end
it "returns after(:all) actions in the reverse order they were defined" do
@state.after(:all, &@a)
@state.after(:all, &@b)
- @state.post(:all).should == [@b, @a, @c]
+ expect(@state.post(:all)).to eq([@b, @a, @c])
end
end
-describe ContextState, "#protect" do
+RSpec.describe ContextState, "#protect" do
before :each do
ScratchPad.record []
@a = lambda {|*| ScratchPad << :a }
@@ -207,41 +207,41 @@ describe ContextState, "#protect" do
end
it "returns true and does execute any blocks if check and MSpec.mode?(:pretend) are true" do
- MSpec.should_receive(:mode?).with(:pretend).and_return(true)
- ContextState.new("").protect("message", [@a, @b]).should be_true
- ScratchPad.recorded.should == []
+ expect(MSpec).to receive(:mode?).with(:pretend).and_return(true)
+ expect(ContextState.new("").protect("message", [@a, @b])).to be_truthy
+ expect(ScratchPad.recorded).to eq([])
end
it "executes the blocks if MSpec.mode?(:pretend) is false" do
- MSpec.should_receive(:mode?).with(:pretend).and_return(false)
+ expect(MSpec).to receive(:mode?).with(:pretend).and_return(false)
ContextState.new("").protect("message", [@a, @b])
- ScratchPad.recorded.should == [:a, :b]
+ expect(ScratchPad.recorded).to eq([:a, :b])
end
it "executes the blocks if check is false" do
ContextState.new("").protect("message", [@a, @b], false)
- ScratchPad.recorded.should == [:a, :b]
+ expect(ScratchPad.recorded).to eq([:a, :b])
end
it "returns true if none of the blocks raise an exception" do
- ContextState.new("").protect("message", [@a, @b]).should be_true
+ expect(ContextState.new("").protect("message", [@a, @b])).to be_truthy
end
it "returns false if any of the blocks raise an exception" do
- ContextState.new("").protect("message", [@a, @c, @b]).should be_false
+ expect(ContextState.new("").protect("message", [@a, @c, @b])).to be_falsey
end
end
-describe ContextState, "#parent=" do
+RSpec.describe ContextState, "#parent=" do
before :each do
@state = ContextState.new ""
@parent = double("describe")
- @parent.stub(:parent).and_return(nil)
- @parent.stub(:child)
+ allow(@parent).to receive(:parent).and_return(nil)
+ allow(@parent).to receive(:child)
end
it "does not set self as a child of parent if shared" do
- @parent.should_not_receive(:child)
+ expect(@parent).not_to receive(:child)
state = ContextState.new "", :shared => true
state.parent = @parent
end
@@ -249,70 +249,70 @@ describe ContextState, "#parent=" do
it "does not set parents if shared" do
state = ContextState.new "", :shared => true
state.parent = @parent
- state.parents.should == [state]
+ expect(state.parents).to eq([state])
end
it "sets self as a child of parent" do
- @parent.should_receive(:child).with(@state)
+ expect(@parent).to receive(:child).with(@state)
@state.parent = @parent
end
it "creates the list of parents" do
@state.parent = @parent
- @state.parents.should == [@parent, @state]
+ expect(@state.parents).to eq([@parent, @state])
end
end
-describe ContextState, "#parent" do
+RSpec.describe ContextState, "#parent" do
before :each do
@state = ContextState.new ""
@parent = double("describe")
- @parent.stub(:parent).and_return(nil)
- @parent.stub(:child)
+ allow(@parent).to receive(:parent).and_return(nil)
+ allow(@parent).to receive(:child)
end
it "returns nil if parent has not been set" do
- @state.parent.should be_nil
+ expect(@state.parent).to be_nil
end
it "returns the parent" do
@state.parent = @parent
- @state.parent.should == @parent
+ expect(@state.parent).to eq(@parent)
end
end
-describe ContextState, "#parents" do
+RSpec.describe ContextState, "#parents" do
before :each do
@first = ContextState.new ""
@second = ContextState.new ""
@parent = double("describe")
- @parent.stub(:parent).and_return(nil)
- @parent.stub(:child)
+ allow(@parent).to receive(:parent).and_return(nil)
+ allow(@parent).to receive(:child)
end
it "returns a list of all enclosing ContextState instances" do
@first.parent = @parent
@second.parent = @first
- @second.parents.should == [@parent, @first, @second]
+ expect(@second.parents).to eq([@parent, @first, @second])
end
end
-describe ContextState, "#child" do
+RSpec.describe ContextState, "#child" do
before :each do
@first = ContextState.new ""
@second = ContextState.new ""
@parent = double("describe")
- @parent.stub(:parent).and_return(nil)
- @parent.stub(:child)
+ allow(@parent).to receive(:parent).and_return(nil)
+ allow(@parent).to receive(:child)
end
it "adds the ContextState to the list of contained ContextStates" do
@first.child @second
- @first.children.should == [@second]
+ expect(@first.children).to eq([@second])
end
end
-describe ContextState, "#children" do
+RSpec.describe ContextState, "#children" do
before :each do
@parent = ContextState.new ""
@first = ContextState.new ""
@@ -322,12 +322,12 @@ describe ContextState, "#children" do
it "returns the list of directly contained ContextStates" do
@first.parent = @parent
@second.parent = @first
- @parent.children.should == [@first]
- @first.children.should == [@second]
+ expect(@parent.children).to eq([@first])
+ expect(@first.children).to eq([@second])
end
end
-describe ContextState, "#state" do
+RSpec.describe ContextState, "#state" do
before :each do
MSpec.store :before, []
MSpec.store :after, []
@@ -336,7 +336,7 @@ describe ContextState, "#state" do
end
it "returns nil if no spec is being executed" do
- @state.state.should == nil
+ expect(@state.state).to eq(nil)
end
it "returns a ExampleState instance if an example is being executed" do
@@ -344,16 +344,16 @@ describe ContextState, "#state" do
@state.describe { }
@state.it("") { ScratchPad.record ScratchPad.recorded.state }
@state.process
- @state.state.should == nil
- ScratchPad.recorded.should be_kind_of(ExampleState)
+ expect(@state.state).to eq(nil)
+ expect(ScratchPad.recorded).to be_kind_of(ExampleState)
end
end
-describe ContextState, "#process" do
+RSpec.describe ContextState, "#process" do
before :each do
MSpec.store :before, []
MSpec.store :after, []
- MSpec.stub(:register_current)
+ allow(MSpec).to receive(:register_current)
@state = ContextState.new ""
@state.describe { }
@@ -368,7 +368,7 @@ describe ContextState, "#process" do
@state.before(:all, &@b)
@state.it("") { }
@state.process
- ScratchPad.recorded.should == [:a, :b]
+ expect(ScratchPad.recorded).to eq([:a, :b])
end
it "calls each after(:all) block" do
@@ -376,22 +376,22 @@ describe ContextState, "#process" do
@state.after(:all, &@b)
@state.it("") { }
@state.process
- ScratchPad.recorded.should == [:b, :a]
+ expect(ScratchPad.recorded).to eq([:b, :a])
end
it "calls each it block" do
@state.it("one", &@a)
@state.it("two", &@b)
@state.process
- ScratchPad.recorded.should == [:a, :b]
+ expect(ScratchPad.recorded).to eq([:a, :b])
end
it "does not call the #it block if #filtered? returns true" do
@state.it("one", &@a)
@state.it("two", &@b)
- @state.examples.first.stub(:filtered?).and_return(true)
+ allow(@state.examples.first).to receive(:filtered?).and_return(true)
@state.process
- ScratchPad.recorded.should == [:b]
+ expect(ScratchPad.recorded).to eq([:b])
end
it "calls each before(:each) block" do
@@ -399,7 +399,7 @@ describe ContextState, "#process" do
@state.before(:each, &@b)
@state.it("") { }
@state.process
- ScratchPad.recorded.should == [:a, :b]
+ expect(ScratchPad.recorded).to eq([:a, :b])
end
it "calls each after(:each) block" do
@@ -407,20 +407,20 @@ describe ContextState, "#process" do
@state.after(:each, &@b)
@state.it("") { }
@state.process
- ScratchPad.recorded.should == [:b, :a]
+ expect(ScratchPad.recorded).to eq([:b, :a])
end
it "calls Mock.cleanup for each it block" do
@state.it("") { }
@state.it("") { }
- Mock.should_receive(:cleanup).twice
+ expect(Mock).to receive(:cleanup).twice
@state.process
end
it "calls Mock.verify_count for each it block" do
@state.it("") { }
@state.it("") { }
- Mock.should_receive(:verify_count).twice
+ expect(Mock).to receive(:verify_count).twice
@state.process
end
@@ -428,7 +428,7 @@ describe ContextState, "#process" do
ScratchPad.record []
@state.describe { ScratchPad << :a }
@state.process
- ScratchPad.recorded.should == [:a]
+ expect(ScratchPad.recorded).to eq([:a])
end
it "creates a new ExampleState instance for each example" do
@@ -436,21 +436,21 @@ describe ContextState, "#process" do
@state.describe { }
@state.it("it") { ScratchPad.record ScratchPad.recorded.state }
@state.process
- ScratchPad.recorded.should be_kind_of(ExampleState)
+ expect(ScratchPad.recorded).to be_kind_of(ExampleState)
end
it "clears the expectations flag before evaluating the #it block" do
MSpec.clear_expectations
- MSpec.should_receive(:clear_expectations)
+ expect(MSpec).to receive(:clear_expectations)
@state.it("it") { ScratchPad.record MSpec.expectation? }
@state.process
- ScratchPad.recorded.should be_false
+ expect(ScratchPad.recorded).to be_falsey
end
it "shuffles the spec list if MSpec.randomize? is true" do
MSpec.randomize = true
begin
- MSpec.should_receive(:shuffle)
+ expect(MSpec).to receive(:shuffle)
@state.it("") { }
@state.process
ensure
@@ -459,24 +459,24 @@ describe ContextState, "#process" do
end
it "sets the current MSpec ContextState" do
- MSpec.should_receive(:register_current).with(@state)
+ expect(MSpec).to receive(:register_current).with(@state)
@state.process
end
it "resets the current MSpec ContextState to nil when there are examples" do
- MSpec.should_receive(:register_current).with(nil)
+ expect(MSpec).to receive(:register_current).with(nil)
@state.it("") { }
@state.process
end
it "resets the current MSpec ContextState to nil when there are no examples" do
- MSpec.should_receive(:register_current).with(nil)
+ expect(MSpec).to receive(:register_current).with(nil)
@state.process
end
it "call #process on children when there are examples" do
child = ContextState.new ""
- child.should_receive(:process)
+ expect(child).to receive(:process)
@state.child child
@state.it("") { }
@state.process
@@ -484,13 +484,13 @@ describe ContextState, "#process" do
it "call #process on children when there are no examples" do
child = ContextState.new ""
- child.should_receive(:process)
+ expect(child).to receive(:process)
@state.child child
@state.process
end
end
-describe ContextState, "#process" do
+RSpec.describe ContextState, "#process" do
before :each do
MSpec.store :exception, []
@@ -514,23 +514,23 @@ describe ContextState, "#process" do
it "raises an SpecExpectationNotFoundError if an #it block does not contain an expectation" do
@state.it("it") { }
@state.process
- ScratchPad.recorded.should == :exception
+ expect(ScratchPad.recorded).to eq(:exception)
end
it "does not raise an SpecExpectationNotFoundError if an #it block does contain an expectation" do
@state.it("it") { MSpec.expectation }
@state.process
- ScratchPad.recorded.should be_nil
+ expect(ScratchPad.recorded).to be_nil
end
it "does not raise an SpecExpectationNotFoundError if the #it block causes a failure" do
@state.it("it") { raise Exception, "Failed!" }
@state.process
- ScratchPad.recorded.should be_nil
+ expect(ScratchPad.recorded).to be_nil
end
end
-describe ContextState, "#process" do
+RSpec.describe ContextState, "#process" do
before :each do
MSpec.store :example, []
@@ -554,18 +554,18 @@ describe ContextState, "#process" do
@state.it("") { MSpec.expectation }
@state.process
- ScratchPad.recorded.first.should be_kind_of(ExampleState)
- ScratchPad.recorded.last.should be_kind_of(Proc)
+ expect(ScratchPad.recorded.first).to be_kind_of(ExampleState)
+ expect(ScratchPad.recorded.last).to be_kind_of(Proc)
end
it "does not call registered example actions if the example has no block" do
@state.it("empty example")
@state.process
- ScratchPad.recorded.should == []
+ expect(ScratchPad.recorded).to eq([])
end
end
-describe ContextState, "#process" do
+RSpec.describe ContextState, "#process" do
before :each do
MSpec.store :before, []
MSpec.store :after, []
@@ -582,30 +582,30 @@ describe ContextState, "#process" do
it "calls registered :before actions with the current ExampleState instance" do
before = double("before")
- before.should_receive(:before).and_return {
+ expect(before).to receive(:before) {
ScratchPad.record :before
@spec_state = @state.state
}
MSpec.register :before, before
@state.process
- ScratchPad.recorded.should == :before
- @spec_state.should be_kind_of(ExampleState)
+ expect(ScratchPad.recorded).to eq(:before)
+ expect(@spec_state).to be_kind_of(ExampleState)
end
it "calls registered :after actions with the current ExampleState instance" do
after = double("after")
- after.should_receive(:after).and_return {
+ expect(after).to receive(:after) {
ScratchPad.record :after
@spec_state = @state.state
}
MSpec.register :after, after
@state.process
- ScratchPad.recorded.should == :after
- @spec_state.should be_kind_of(ExampleState)
+ expect(ScratchPad.recorded).to eq(:after)
+ expect(@spec_state).to be_kind_of(ExampleState)
end
end
-describe ContextState, "#process" do
+RSpec.describe ContextState, "#process" do
before :each do
MSpec.store :enter, []
MSpec.store :leave, []
@@ -622,22 +622,22 @@ describe ContextState, "#process" do
it "calls registered :enter actions with the current #describe string" do
enter = double("enter")
- enter.should_receive(:enter).with("C#m").and_return { ScratchPad.record :enter }
+ expect(enter).to receive(:enter).with("C#m") { ScratchPad.record :enter }
MSpec.register :enter, enter
@state.process
- ScratchPad.recorded.should == :enter
+ expect(ScratchPad.recorded).to eq(:enter)
end
it "calls registered :leave actions" do
leave = double("leave")
- leave.should_receive(:leave).and_return { ScratchPad.record :leave }
+ expect(leave).to receive(:leave) { ScratchPad.record :leave }
MSpec.register :leave, leave
@state.process
- ScratchPad.recorded.should == :leave
+ expect(ScratchPad.recorded).to eq(:leave)
end
end
-describe ContextState, "#process when an exception is raised in before(:all)" do
+RSpec.describe ContextState, "#process when an exception is raised in before(:all)" do
before :each do
MSpec.store :before, []
MSpec.store :after, []
@@ -661,43 +661,43 @@ describe ContextState, "#process when an exception is raised in before(:all)" do
@state.before(:each, &@a)
@state.it("") { }
@state.process
- ScratchPad.recorded.should == []
+ expect(ScratchPad.recorded).to eq([])
end
it "does not call the it block" do
@state.it("one", &@a)
@state.process
- ScratchPad.recorded.should == []
+ expect(ScratchPad.recorded).to eq([])
end
it "does not call after(:each)" do
@state.after(:each, &@a)
@state.it("") { }
@state.process
- ScratchPad.recorded.should == []
+ expect(ScratchPad.recorded).to eq([])
end
it "does not call after(:each)" do
@state.after(:all, &@a)
@state.it("") { }
@state.process
- ScratchPad.recorded.should == []
+ expect(ScratchPad.recorded).to eq([])
end
it "does not call Mock.verify_count" do
@state.it("") { }
- Mock.should_not_receive(:verify_count)
+ expect(Mock).not_to receive(:verify_count)
@state.process
end
it "calls Mock.cleanup" do
@state.it("") { }
- Mock.should_receive(:cleanup)
+ expect(Mock).to receive(:cleanup)
@state.process
end
end
-describe ContextState, "#process when an exception is raised in before(:each)" do
+RSpec.describe ContextState, "#process when an exception is raised in before(:each)" do
before :each do
MSpec.store :before, []
MSpec.store :after, []
@@ -720,24 +720,24 @@ describe ContextState, "#process when an exception is raised in before(:each)" d
it "does not call the it block" do
@state.it("one", &@a)
@state.process
- ScratchPad.recorded.should == []
+ expect(ScratchPad.recorded).to eq([])
end
- it "does call after(:each)" do
+ it "calls after(:each)" do
@state.after(:each, &@a)
@state.it("") { }
@state.process
- ScratchPad.recorded.should == [:a]
+ expect(ScratchPad.recorded).to eq([:a])
end
- it "does not call Mock.verify_count" do
+ it "calls Mock.verify_count" do
@state.it("") { }
- Mock.should_not_receive(:verify_count)
+ expect(Mock).to receive(:verify_count)
@state.process
end
end
-describe ContextState, "#process in pretend mode" do
+RSpec.describe ContextState, "#process in pretend mode" do
before :all do
MSpec.register_mode :pretend
end
@@ -763,30 +763,30 @@ describe ContextState, "#process in pretend mode" do
it "calls registered :before actions with the current ExampleState instance" do
before = double("before")
- before.should_receive(:before).and_return {
+ expect(before).to receive(:before) {
ScratchPad.record :before
@spec_state = @state.state
}
MSpec.register :before, before
@state.process
- ScratchPad.recorded.should == :before
- @spec_state.should be_kind_of(ExampleState)
+ expect(ScratchPad.recorded).to eq(:before)
+ expect(@spec_state).to be_kind_of(ExampleState)
end
it "calls registered :after actions with the current ExampleState instance" do
after = double("after")
- after.should_receive(:after).and_return {
+ expect(after).to receive(:after) {
ScratchPad.record :after
@spec_state = @state.state
}
MSpec.register :after, after
@state.process
- ScratchPad.recorded.should == :after
- @spec_state.should be_kind_of(ExampleState)
+ expect(ScratchPad.recorded).to eq(:after)
+ expect(@spec_state).to be_kind_of(ExampleState)
end
end
-describe ContextState, "#process in pretend mode" do
+RSpec.describe ContextState, "#process in pretend mode" do
before :all do
MSpec.register_mode :pretend
end
@@ -811,7 +811,7 @@ describe ContextState, "#process in pretend mode" do
ScratchPad.record []
@state.describe { ScratchPad << :a }
@state.process
- ScratchPad.recorded.should == [:a]
+ expect(ScratchPad.recorded).to eq([:a])
end
it "does not call any before(:all) block" do
@@ -819,7 +819,7 @@ describe ContextState, "#process in pretend mode" do
@state.before(:all, &@b)
@state.it("") { }
@state.process
- ScratchPad.recorded.should == []
+ expect(ScratchPad.recorded).to eq([])
end
it "does not call any after(:all) block" do
@@ -827,14 +827,14 @@ describe ContextState, "#process in pretend mode" do
@state.after(:all, &@b)
@state.it("") { }
@state.process
- ScratchPad.recorded.should == []
+ expect(ScratchPad.recorded).to eq([])
end
it "does not call any it block" do
@state.it("one", &@a)
@state.it("two", &@b)
@state.process
- ScratchPad.recorded.should == []
+ expect(ScratchPad.recorded).to eq([])
end
it "does not call any before(:each) block" do
@@ -842,7 +842,7 @@ describe ContextState, "#process in pretend mode" do
@state.before(:each, &@b)
@state.it("") { }
@state.process
- ScratchPad.recorded.should == []
+ expect(ScratchPad.recorded).to eq([])
end
it "does not call any after(:each) block" do
@@ -850,18 +850,18 @@ describe ContextState, "#process in pretend mode" do
@state.after(:each, &@b)
@state.it("") { }
@state.process
- ScratchPad.recorded.should == []
+ expect(ScratchPad.recorded).to eq([])
end
it "does not call Mock.cleanup" do
@state.it("") { }
@state.it("") { }
- Mock.should_not_receive(:cleanup)
+ expect(Mock).not_to receive(:cleanup)
@state.process
end
end
-describe ContextState, "#process in pretend mode" do
+RSpec.describe ContextState, "#process in pretend mode" do
before :all do
MSpec.register_mode :pretend
end
@@ -886,26 +886,26 @@ describe ContextState, "#process in pretend mode" do
it "calls registered :enter actions with the current #describe string" do
enter = double("enter")
- enter.should_receive(:enter).and_return { ScratchPad.record :enter }
+ expect(enter).to receive(:enter) { ScratchPad.record :enter }
MSpec.register :enter, enter
@state.process
- ScratchPad.recorded.should == :enter
+ expect(ScratchPad.recorded).to eq(:enter)
end
it "calls registered :leave actions" do
leave = double("leave")
- leave.should_receive(:leave).and_return { ScratchPad.record :leave }
+ expect(leave).to receive(:leave) { ScratchPad.record :leave }
MSpec.register :leave, leave
@state.process
- ScratchPad.recorded.should == :leave
+ expect(ScratchPad.recorded).to eq(:leave)
end
end
-describe ContextState, "#it_should_behave_like" do
+RSpec.describe ContextState, "#it_should_behave_like" do
before :each do
@shared_desc = :shared_context
@shared = ContextState.new(@shared_desc, :shared => true)
- MSpec.stub(:retrieve_shared).and_return(@shared)
+ allow(MSpec).to receive(:retrieve_shared).and_return(@shared)
@state = ContextState.new "Top level"
@a = lambda {|*| }
@@ -913,8 +913,8 @@ describe ContextState, "#it_should_behave_like" do
end
it "raises an Exception if unable to find the shared ContextState" do
- MSpec.should_receive(:retrieve_shared).and_return(nil)
- lambda { @state.it_should_behave_like "this" }.should raise_error(Exception)
+ expect(MSpec).to receive(:retrieve_shared).and_return(nil)
+ expect { @state.it_should_behave_like "this" }.to raise_error(Exception)
end
describe "for nested ContextState instances" do
@@ -925,24 +925,24 @@ describe ContextState, "#it_should_behave_like" do
@shared.children << @nested
@nested_dup = @nested.dup
- @nested.stub(:dup).and_return(@nested_dup)
+ allow(@nested).to receive(:dup).and_return(@nested_dup)
end
it "duplicates the nested ContextState" do
@state.it_should_behave_like @shared_desc
- @state.children.first.should equal(@nested_dup)
+ expect(@state.children.first).to equal(@nested_dup)
end
it "sets the parent of the nested ContextState to the containing ContextState" do
@state.it_should_behave_like @shared_desc
- @nested_dup.parent.should equal(@state)
+ expect(@nested_dup.parent).to equal(@state)
end
it "sets the context for nested examples to the nested ContextState's dup" do
@shared.it "an example", &@a
@shared.it "another example", &@b
@state.it_should_behave_like @shared_desc
- @nested_dup.examples.each { |x| x.context.should equal(@nested_dup) }
+ @nested_dup.examples.each { |x| expect(x.context).to equal(@nested_dup) }
end
it "omits the shored ContextState's description" do
@@ -950,58 +950,58 @@ describe ContextState, "#it_should_behave_like" do
@nested.it "another example", &@b
@state.it_should_behave_like @shared_desc
- @nested_dup.description.should == "Top level nested context"
- @nested_dup.examples.first.description.should == "Top level nested context an example"
- @nested_dup.examples.last.description.should == "Top level nested context another example"
+ expect(@nested_dup.description).to eq("Top level nested context")
+ expect(@nested_dup.examples.first.description).to eq("Top level nested context an example")
+ expect(@nested_dup.examples.last.description).to eq("Top level nested context another example")
end
end
it "adds duped examples from the shared ContextState" do
@shared.it "some method", &@a
ex_dup = @shared.examples.first.dup
- @shared.examples.first.stub(:dup).and_return(ex_dup)
+ allow(@shared.examples.first).to receive(:dup).and_return(ex_dup)
@state.it_should_behave_like @shared_desc
- @state.examples.should == [ex_dup]
+ expect(@state.examples).to eq([ex_dup])
end
it "sets the context for examples to the containing ContextState" do
@shared.it "an example", &@a
@shared.it "another example", &@b
@state.it_should_behave_like @shared_desc
- @state.examples.each { |x| x.context.should equal(@state) }
+ @state.examples.each { |x| expect(x.context).to equal(@state) }
end
it "adds before(:all) blocks from the shared ContextState" do
@shared.before :all, &@a
@shared.before :all, &@b
@state.it_should_behave_like @shared_desc
- @state.before(:all).should include(*@shared.before(:all))
+ expect(@state.before(:all)).to include(*@shared.before(:all))
end
it "adds before(:each) blocks from the shared ContextState" do
@shared.before :each, &@a
@shared.before :each, &@b
@state.it_should_behave_like @shared_desc
- @state.before(:each).should include(*@shared.before(:each))
+ expect(@state.before(:each)).to include(*@shared.before(:each))
end
it "adds after(:each) blocks from the shared ContextState" do
@shared.after :each, &@a
@shared.after :each, &@b
@state.it_should_behave_like @shared_desc
- @state.after(:each).should include(*@shared.after(:each))
+ expect(@state.after(:each)).to include(*@shared.after(:each))
end
it "adds after(:all) blocks from the shared ContextState" do
@shared.after :all, &@a
@shared.after :all, &@b
@state.it_should_behave_like @shared_desc
- @state.after(:all).should include(*@shared.after(:all))
+ expect(@state.after(:all)).to include(*@shared.after(:all))
end
end
-describe ContextState, "#filter_examples" do
+RSpec.describe ContextState, "#filter_examples" do
before :each do
@state = ContextState.new ""
@state.it("one") { }
@@ -1009,20 +1009,20 @@ describe ContextState, "#filter_examples" do
end
it "removes examples that are filtered" do
- @state.examples.first.stub(:filtered?).and_return(true)
- @state.examples.size.should == 2
+ allow(@state.examples.first).to receive(:filtered?).and_return(true)
+ expect(@state.examples.size).to eq(2)
@state.filter_examples
- @state.examples.size.should == 1
+ expect(@state.examples.size).to eq(1)
end
it "returns true if there are remaining examples to evaluate" do
- @state.examples.first.stub(:filtered?).and_return(true)
- @state.filter_examples.should be_true
+ allow(@state.examples.first).to receive(:filtered?).and_return(true)
+ expect(@state.filter_examples).to be_truthy
end
it "returns false if there are no remaining examples to evaluate" do
- @state.examples.first.stub(:filtered?).and_return(true)
- @state.examples.last.stub(:filtered?).and_return(true)
- @state.filter_examples.should be_false
+ allow(@state.examples.first).to receive(:filtered?).and_return(true)
+ allow(@state.examples.last).to receive(:filtered?).and_return(true)
+ expect(@state.filter_examples).to be_falsey
end
end