diff options
author | Benoit Daloze <eregontp@gmail.com> | 2021-03-27 13:02:38 +0100 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2021-03-27 13:02:38 +0100 |
commit | 44736a6b7a2b3475db2d05187f33e3c1a7b4b4e5 (patch) | |
tree | 4cb679a8742121782a50e72e01160d19f479f9a6 /spec/mspec/spec/runner | |
parent | 31ae931e166825450dcc16d470553e67281951a2 (diff) |
Update to ruby/mspec@d1adf59
Diffstat (limited to 'spec/mspec/spec/runner')
28 files changed, 1081 insertions, 1061 deletions
diff --git a/spec/mspec/spec/runner/actions/filter_spec.rb b/spec/mspec/spec/runner/actions/filter_spec.rb index d185781757..7582b31c1d 100644 --- a/spec/mspec/spec/runner/actions/filter_spec.rb +++ b/spec/mspec/spec/runner/actions/filter_spec.rb @@ -3,82 +3,82 @@ require 'mspec/runner/actions/filter' require 'mspec/runner/mspec' require 'mspec/runner/tag' -describe ActionFilter do +RSpec.describe ActionFilter do it "creates a filter when not passed a description" do - MatchFilter.should_not_receive(:new) + expect(MatchFilter).not_to receive(:new) ActionFilter.new(nil, nil) end it "creates a filter from a single description" do - MatchFilter.should_receive(:new).with(nil, "match me") + expect(MatchFilter).to receive(:new).with(nil, "match me") ActionFilter.new(nil, "match me") end it "creates a filter from an array of descriptions" do - MatchFilter.should_receive(:new).with(nil, "match me", "again") + expect(MatchFilter).to receive(:new).with(nil, "match me", "again") ActionFilter.new(nil, ["match me", "again"]) end end -describe ActionFilter, "#===" do +RSpec.describe ActionFilter, "#===" do before :each do - MSpec.stub(:read_tags).and_return(["match"]) + allow(MSpec).to receive(:read_tags).and_return(["match"]) @action = ActionFilter.new(nil, ["catch", "if you"]) end it "returns false if there are no filters" do action = ActionFilter.new - action.===("anything").should == false + expect(action.===("anything")).to eq(false) end it "returns true if the argument matches any of the descriptions" do - @action.===("catch").should == true - @action.===("if you can").should == true + expect(@action.===("catch")).to eq(true) + expect(@action.===("if you can")).to eq(true) end it "returns false if the argument does not match any of the descriptions" do - @action.===("patch me").should == false - @action.===("if I can").should == false + expect(@action.===("patch me")).to eq(false) + expect(@action.===("if I can")).to eq(false) end end -describe ActionFilter, "#load" do +RSpec.describe ActionFilter, "#load" do before :each do @tag = SpecTag.new "tag(comment):description" end it "creates a filter from a single tag" do - MSpec.should_receive(:read_tags).with(["tag"]).and_return([@tag]) - MatchFilter.should_receive(:new).with(nil, "description") + expect(MSpec).to receive(:read_tags).with(["tag"]).and_return([@tag]) + expect(MatchFilter).to receive(:new).with(nil, "description") ActionFilter.new("tag", nil).load end it "creates a filter from an array of tags" do - MSpec.should_receive(:read_tags).with(["tag", "key"]).and_return([@tag]) - MatchFilter.should_receive(:new).with(nil, "description") + expect(MSpec).to receive(:read_tags).with(["tag", "key"]).and_return([@tag]) + expect(MatchFilter).to receive(:new).with(nil, "description") ActionFilter.new(["tag", "key"], nil).load end it "creates a filter from both tags and descriptions" do - MSpec.should_receive(:read_tags).and_return([@tag]) + expect(MSpec).to receive(:read_tags).and_return([@tag]) filter = ActionFilter.new("tag", ["match me", "again"]) - MatchFilter.should_receive(:new).with(nil, "description") + expect(MatchFilter).to receive(:new).with(nil, "description") filter.load end end -describe ActionFilter, "#register" do +RSpec.describe ActionFilter, "#register" do it "registers itself with MSpec for the :load actions" do filter = ActionFilter.new - MSpec.should_receive(:register).with(:load, filter) + expect(MSpec).to receive(:register).with(:load, filter) filter.register end end -describe ActionFilter, "#unregister" do +RSpec.describe ActionFilter, "#unregister" do it "unregisters itself with MSpec for the :load actions" do filter = ActionFilter.new - MSpec.should_receive(:unregister).with(:load, filter) + expect(MSpec).to receive(:unregister).with(:load, filter) filter.unregister end end diff --git a/spec/mspec/spec/runner/actions/tag_spec.rb b/spec/mspec/spec/runner/actions/tag_spec.rb index 92df362d02..738e9a18c9 100644 --- a/spec/mspec/spec/runner/actions/tag_spec.rb +++ b/spec/mspec/spec/runner/actions/tag_spec.rb @@ -4,211 +4,211 @@ require 'mspec/runner/mspec' require 'mspec/runner/example' require 'mspec/runner/tag' -describe TagAction, ".new" do +RSpec.describe TagAction, ".new" do it "creates an MatchFilter with its tag and desc arguments" do filter = double('action filter').as_null_object - MatchFilter.should_receive(:new).with(nil, "some", "thing").and_return(filter) + expect(MatchFilter).to receive(:new).with(nil, "some", "thing").and_return(filter) TagAction.new :add, :all, nil, nil, ["tag", "key"], ["some", "thing"] end end -describe TagAction, "#===" do +RSpec.describe TagAction, "#===" do before :each do - MSpec.stub(:read_tags).and_return(["match"]) + allow(MSpec).to receive(:read_tags).and_return(["match"]) @action = TagAction.new :add, :fail, nil, nil, nil, ["catch", "if you"] end it "returns true if there are no filters" do action = TagAction.new :add, :all, nil, nil - action.===("anything").should == true + expect(action.===("anything")).to eq(true) end it "returns true if the argument matches any of the descriptions" do - @action.===("catch").should == true - @action.===("if you can").should == true + expect(@action.===("catch")).to eq(true) + expect(@action.===("if you can")).to eq(true) end it "returns false if the argument does not match any of the descriptions" do - @action.===("patch me").should == false - @action.===("if I can").should == false + expect(@action.===("patch me")).to eq(false) + expect(@action.===("if I can")).to eq(false) end end -describe TagAction, "#exception?" do +RSpec.describe TagAction, "#exception?" do before :each do @action = TagAction.new :add, :fail, nil, nil, nil, nil end it "returns false if no exception has been raised while evaluating an example" do - @action.exception?.should be_false + expect(@action.exception?).to be_falsey end it "returns true if an exception was raised while evaluating an example" do @action.exception ExceptionState.new nil, nil, Exception.new("failed") - @action.exception?.should be_true + expect(@action.exception?).to be_truthy end end -describe TagAction, "#outcome?" do +RSpec.describe TagAction, "#outcome?" do before :each do - MSpec.stub(:read_tags).and_return([]) + allow(MSpec).to receive(:read_tags).and_return([]) @exception = ExceptionState.new nil, nil, Exception.new("failed") end it "returns true if outcome is :fail and the spec fails" do action = TagAction.new :add, :fail, nil, nil, nil, nil action.exception @exception - action.outcome?.should == true + expect(action.outcome?).to eq(true) end it "returns false if the outcome is :fail and the spec passes" do action = TagAction.new :add, :fail, nil, nil, nil, nil - action.outcome?.should == false + expect(action.outcome?).to eq(false) end it "returns true if the outcome is :pass and the spec passes" do action = TagAction.new :del, :pass, nil, nil, nil, nil - action.outcome?.should == true + expect(action.outcome?).to eq(true) end it "returns false if the outcome is :pass and the spec fails" do action = TagAction.new :del, :pass, nil, nil, nil, nil action.exception @exception - action.outcome?.should == false + expect(action.outcome?).to eq(false) end it "returns true if the outcome is :all" do action = TagAction.new :add, :all, nil, nil, nil, nil action.exception @exception - action.outcome?.should == true + expect(action.outcome?).to eq(true) end end -describe TagAction, "#before" do +RSpec.describe TagAction, "#before" do it "resets the #exception? flag to false" do action = TagAction.new :add, :fail, nil, nil, nil, nil - action.exception?.should be_false + expect(action.exception?).to be_falsey action.exception ExceptionState.new(nil, nil, Exception.new("Fail!")) - action.exception?.should be_true + expect(action.exception?).to be_truthy action.before(ExampleState.new(ContextState.new("describe"), "it")) - action.exception?.should be_false + expect(action.exception?).to be_falsey end end -describe TagAction, "#exception" do +RSpec.describe TagAction, "#exception" do it "sets the #exception? flag" do action = TagAction.new :add, :fail, nil, nil, nil, nil - action.exception?.should be_false + expect(action.exception?).to be_falsey action.exception ExceptionState.new(nil, nil, Exception.new("Fail!")) - action.exception?.should be_true + expect(action.exception?).to be_truthy end end -describe TagAction, "#after when action is :add" do +RSpec.describe TagAction, "#after when action is :add" do before :each do - MSpec.stub(:read_tags).and_return([]) + allow(MSpec).to receive(:read_tags).and_return([]) context = ContextState.new "Catch#me" @state = ExampleState.new context, "if you can" @tag = SpecTag.new "tag(comment):Catch#me if you can" - SpecTag.stub(:new).and_return(@tag) + allow(SpecTag).to receive(:new).and_return(@tag) @exception = ExceptionState.new nil, nil, Exception.new("failed") end it "does not write a tag if the description does not match" do - MSpec.should_not_receive(:write_tag) + expect(MSpec).not_to receive(:write_tag) action = TagAction.new :add, :all, "tag", "comment", nil, "match" action.after @state end it "does not write a tag if outcome is :fail and the spec passed" do - MSpec.should_not_receive(:write_tag) + expect(MSpec).not_to receive(:write_tag) action = TagAction.new :add, :fail, "tag", "comment", nil, "can" action.after @state end it "writes a tag if the outcome is :fail and the spec failed" do - MSpec.should_receive(:write_tag).with(@tag) + expect(MSpec).to receive(:write_tag).with(@tag) action = TagAction.new :add, :fail, "tag", "comment", nil, "can" action.exception @exception action.after @state end it "does not write a tag if outcome is :pass and the spec failed" do - MSpec.should_not_receive(:write_tag) + expect(MSpec).not_to receive(:write_tag) action = TagAction.new :add, :pass, "tag", "comment", nil, "can" action.exception @exception action.after @state end it "writes a tag if the outcome is :pass and the spec passed" do - MSpec.should_receive(:write_tag).with(@tag) + expect(MSpec).to receive(:write_tag).with(@tag) action = TagAction.new :add, :pass, "tag", "comment", nil, "can" action.after @state end it "writes a tag if the outcome is :all" do - MSpec.should_receive(:write_tag).with(@tag) + expect(MSpec).to receive(:write_tag).with(@tag) action = TagAction.new :add, :all, "tag", "comment", nil, "can" action.after @state end end -describe TagAction, "#after when action is :del" do +RSpec.describe TagAction, "#after when action is :del" do before :each do - MSpec.stub(:read_tags).and_return([]) + allow(MSpec).to receive(:read_tags).and_return([]) context = ContextState.new "Catch#me" @state = ExampleState.new context, "if you can" @tag = SpecTag.new "tag(comment):Catch#me if you can" - SpecTag.stub(:new).and_return(@tag) + allow(SpecTag).to receive(:new).and_return(@tag) @exception = ExceptionState.new nil, nil, Exception.new("failed") end it "does not delete a tag if the description does not match" do - MSpec.should_not_receive(:delete_tag) + expect(MSpec).not_to receive(:delete_tag) action = TagAction.new :del, :all, "tag", "comment", nil, "match" action.after @state end it "does not delete a tag if outcome is :fail and the spec passed" do - MSpec.should_not_receive(:delete_tag) + expect(MSpec).not_to receive(:delete_tag) action = TagAction.new :del, :fail, "tag", "comment", nil, "can" action.after @state end it "deletes a tag if the outcome is :fail and the spec failed" do - MSpec.should_receive(:delete_tag).with(@tag) + expect(MSpec).to receive(:delete_tag).with(@tag) action = TagAction.new :del, :fail, "tag", "comment", nil, "can" action.exception @exception action.after @state end it "does not delete a tag if outcome is :pass and the spec failed" do - MSpec.should_not_receive(:delete_tag) + expect(MSpec).not_to receive(:delete_tag) action = TagAction.new :del, :pass, "tag", "comment", nil, "can" action.exception @exception action.after @state end it "deletes a tag if the outcome is :pass and the spec passed" do - MSpec.should_receive(:delete_tag).with(@tag) + expect(MSpec).to receive(:delete_tag).with(@tag) action = TagAction.new :del, :pass, "tag", "comment", nil, "can" action.after @state end it "deletes a tag if the outcome is :all" do - MSpec.should_receive(:delete_tag).with(@tag) + expect(MSpec).to receive(:delete_tag).with(@tag) action = TagAction.new :del, :all, "tag", "comment", nil, "can" action.after @state end end -describe TagAction, "#finish" do +RSpec.describe TagAction, "#finish" do before :each do $stdout = @out = IOStub.new context = ContextState.new "Catch#me" @state = ExampleState.new context, "if you can" - MSpec.stub(:write_tag).and_return(true) - MSpec.stub(:delete_tag).and_return(true) + allow(MSpec).to receive(:write_tag).and_return(true) + allow(MSpec).to receive(:delete_tag).and_return(true) end after :each do @@ -217,99 +217,97 @@ describe TagAction, "#finish" do it "reports no specs tagged if none where tagged" do action = TagAction.new :add, :fail, "tag", "comment", nil, "can" - action.stub(:outcome?).and_return(false) + allow(action).to receive(:outcome?).and_return(false) action.after @state action.finish - @out.should == "\nTagAction: no specs were tagged with 'tag'\n" + expect(@out).to eq("\nTagAction: no specs were tagged with 'tag'\n") end it "reports no specs tagged if none where tagged" do action = TagAction.new :del, :fail, "tag", "comment", nil, "can" - action.stub(:outcome?).and_return(false) + allow(action).to receive(:outcome?).and_return(false) action.after @state action.finish - @out.should == "\nTagAction: no tags 'tag' were deleted\n" + expect(@out).to eq("\nTagAction: no tags 'tag' were deleted\n") end it "reports the spec descriptions that were tagged" do action = TagAction.new :add, :fail, "tag", "comment", nil, "can" - action.stub(:outcome?).and_return(true) + allow(action).to receive(:outcome?).and_return(true) action.after @state action.finish - @out.should == -%[ + expect(@out).to eq(%[ TagAction: specs tagged with 'tag': Catch#me if you can -] +]) end it "reports the spec descriptions for the tags that were deleted" do action = TagAction.new :del, :fail, "tag", "comment", nil, "can" - action.stub(:outcome?).and_return(true) + allow(action).to receive(:outcome?).and_return(true) action.after @state action.finish - @out.should == -%[ + expect(@out).to eq(%[ TagAction: tag 'tag' deleted for specs: Catch#me if you can -] +]) end end -describe TagAction, "#register" do +RSpec.describe TagAction, "#register" do before :each do - MSpec.stub(:register) - MSpec.stub(:read_tags).and_return([]) + allow(MSpec).to receive(:register) + allow(MSpec).to receive(:read_tags).and_return([]) @action = TagAction.new :add, :all, nil, nil, nil, nil end it "registers itself with MSpec for the :before event" do - MSpec.should_receive(:register).with(:before, @action) + expect(MSpec).to receive(:register).with(:before, @action) @action.register end it "registers itself with MSpec for the :after event" do - MSpec.should_receive(:register).with(:after, @action) + expect(MSpec).to receive(:register).with(:after, @action) @action.register end it "registers itself with MSpec for the :exception event" do - MSpec.should_receive(:register).with(:exception, @action) + expect(MSpec).to receive(:register).with(:exception, @action) @action.register end it "registers itself with MSpec for the :finish event" do - MSpec.should_receive(:register).with(:finish, @action) + expect(MSpec).to receive(:register).with(:finish, @action) @action.register end end -describe TagAction, "#unregister" do +RSpec.describe TagAction, "#unregister" do before :each do - MSpec.stub(:unregister) - MSpec.stub(:read_tags).and_return([]) + allow(MSpec).to receive(:unregister) + allow(MSpec).to receive(:read_tags).and_return([]) @action = TagAction.new :add, :all, nil, nil, nil, nil end it "unregisters itself with MSpec for the :before event" do - MSpec.should_receive(:unregister).with(:before, @action) + expect(MSpec).to receive(:unregister).with(:before, @action) @action.unregister end it "unregisters itself with MSpec for the :after event" do - MSpec.should_receive(:unregister).with(:after, @action) + expect(MSpec).to receive(:unregister).with(:after, @action) @action.unregister end it "unregisters itself with MSpec for the :exception event" do - MSpec.should_receive(:unregister).with(:exception, @action) + expect(MSpec).to receive(:unregister).with(:exception, @action) @action.unregister end it "unregisters itself with MSpec for the :finish event" do - MSpec.should_receive(:unregister).with(:finish, @action) + expect(MSpec).to receive(:unregister).with(:finish, @action) @action.unregister end end diff --git a/spec/mspec/spec/runner/actions/taglist_spec.rb b/spec/mspec/spec/runner/actions/taglist_spec.rb index 418c761c2d..b6a5400f7d 100644 --- a/spec/mspec/spec/runner/actions/taglist_spec.rb +++ b/spec/mspec/spec/runner/actions/taglist_spec.rb @@ -4,34 +4,34 @@ require 'mspec/runner/mspec' require 'mspec/runner/example' require 'mspec/runner/tag' -describe TagListAction, "#include?" do +RSpec.describe TagListAction, "#include?" do it "returns true" do - TagListAction.new.include?(:anything).should be_true + expect(TagListAction.new.include?(:anything)).to be_truthy end end -describe TagListAction, "#===" do +RSpec.describe TagListAction, "#===" do before :each do tag = SpecTag.new "fails:description" - MSpec.stub(:read_tags).and_return([tag]) + allow(MSpec).to receive(:read_tags).and_return([tag]) @filter = double("MatchFilter").as_null_object - MatchFilter.stub(:new).and_return(@filter) + allow(MatchFilter).to receive(:new).and_return(@filter) @action = TagListAction.new @action.load end it "returns true if filter === string returns true" do - @filter.should_receive(:===).with("str").and_return(true) - @action.===("str").should be_true + expect(@filter).to receive(:===).with("str").and_return(true) + expect(@action.===("str")).to be_truthy end it "returns false if filter === string returns false" do - @filter.should_receive(:===).with("str").and_return(false) - @action.===("str").should be_false + expect(@filter).to receive(:===).with("str").and_return(false) + expect(@action.===("str")).to be_falsey end end -describe TagListAction, "#start" do +RSpec.describe TagListAction, "#start" do before :each do @stdout = $stdout $stdout = IOStub.new @@ -44,48 +44,48 @@ describe TagListAction, "#start" do it "prints a banner for specific tags" do action = TagListAction.new ["fails", "unstable"] action.start - $stdout.should == "\nListing specs tagged with 'fails', 'unstable'\n\n" + expect($stdout).to eq("\nListing specs tagged with 'fails', 'unstable'\n\n") end it "prints a banner for all tags" do action = TagListAction.new action.start - $stdout.should == "\nListing all tagged specs\n\n" + expect($stdout).to eq("\nListing all tagged specs\n\n") end end -describe TagListAction, "#load" do +RSpec.describe TagListAction, "#load" do before :each do @t1 = SpecTag.new "fails:I fail" @t2 = SpecTag.new "unstable:I'm unstable" end it "creates a MatchFilter for matching tags" do - MSpec.should_receive(:read_tags).with(["fails"]).and_return([@t1]) - MatchFilter.should_receive(:new).with(nil, "I fail") + expect(MSpec).to receive(:read_tags).with(["fails"]).and_return([@t1]) + expect(MatchFilter).to receive(:new).with(nil, "I fail") TagListAction.new(["fails"]).load end it "creates a MatchFilter for all tags" do - MSpec.should_receive(:read_tags).and_return([@t1, @t2]) - MatchFilter.should_receive(:new).with(nil, "I fail", "I'm unstable") + expect(MSpec).to receive(:read_tags).and_return([@t1, @t2]) + expect(MatchFilter).to receive(:new).with(nil, "I fail", "I'm unstable") TagListAction.new.load end it "does not create a MatchFilter if there are no matching tags" do - MSpec.stub(:read_tags).and_return([]) - MatchFilter.should_not_receive(:new) + allow(MSpec).to receive(:read_tags).and_return([]) + expect(MatchFilter).not_to receive(:new) TagListAction.new(["fails"]).load end end -describe TagListAction, "#after" do +RSpec.describe TagListAction, "#after" do before :each do @stdout = $stdout $stdout = IOStub.new @state = double("ExampleState") - @state.stub(:description).and_return("str") + allow(@state).to receive(:description).and_return("str") @action = TagListAction.new end @@ -95,58 +95,58 @@ describe TagListAction, "#after" do end it "prints nothing if the filter does not match" do - @action.should_receive(:===).with("str").and_return(false) + expect(@action).to receive(:===).with("str").and_return(false) @action.after(@state) - $stdout.should == "" + expect($stdout).to eq("") end it "prints the example description if the filter matches" do - @action.should_receive(:===).with("str").and_return(true) + expect(@action).to receive(:===).with("str").and_return(true) @action.after(@state) - $stdout.should == "str\n" + expect($stdout).to eq("str\n") end end -describe TagListAction, "#register" do +RSpec.describe TagListAction, "#register" do before :each do - MSpec.stub(:register) + allow(MSpec).to receive(:register) @action = TagListAction.new end it "registers itself with MSpec for the :start event" do - MSpec.should_receive(:register).with(:start, @action) + expect(MSpec).to receive(:register).with(:start, @action) @action.register end it "registers itself with MSpec for the :load event" do - MSpec.should_receive(:register).with(:load, @action) + expect(MSpec).to receive(:register).with(:load, @action) @action.register end it "registers itself with MSpec for the :after event" do - MSpec.should_receive(:register).with(:after, @action) + expect(MSpec).to receive(:register).with(:after, @action) @action.register end end -describe TagListAction, "#unregister" do +RSpec.describe TagListAction, "#unregister" do before :each do - MSpec.stub(:unregister) + allow(MSpec).to receive(:unregister) @action = TagListAction.new end it "unregisters itself with MSpec for the :start event" do - MSpec.should_receive(:unregister).with(:start, @action) + expect(MSpec).to receive(:unregister).with(:start, @action) @action.unregister end it "unregisters itself with MSpec for the :load event" do - MSpec.should_receive(:unregister).with(:load, @action) + expect(MSpec).to receive(:unregister).with(:load, @action) @action.unregister end it "unregisters itself with MSpec for the :after event" do - MSpec.should_receive(:unregister).with(:after, @action) + expect(MSpec).to receive(:unregister).with(:after, @action) @action.unregister end end diff --git a/spec/mspec/spec/runner/actions/tagpurge_spec.rb b/spec/mspec/spec/runner/actions/tagpurge_spec.rb index 27ad2a1470..37df0afd5a 100644 --- a/spec/mspec/spec/runner/actions/tagpurge_spec.rb +++ b/spec/mspec/spec/runner/actions/tagpurge_spec.rb @@ -4,7 +4,7 @@ require 'mspec/runner/mspec' require 'mspec/runner/example' require 'mspec/runner/tag' -describe TagPurgeAction, "#start" do +RSpec.describe TagPurgeAction, "#start" do before :each do @stdout = $stdout $stdout = IOStub.new @@ -17,45 +17,45 @@ describe TagPurgeAction, "#start" do it "prints a banner" do action = TagPurgeAction.new action.start - $stdout.should == "\nRemoving tags not matching any specs\n\n" + expect($stdout).to eq("\nRemoving tags not matching any specs\n\n") end end -describe TagPurgeAction, "#load" do +RSpec.describe TagPurgeAction, "#load" do before :each do @t1 = SpecTag.new "fails:I fail" @t2 = SpecTag.new "unstable:I'm unstable" end it "creates a MatchFilter for all tags" do - MSpec.should_receive(:read_tags).and_return([@t1, @t2]) - MatchFilter.should_receive(:new).with(nil, "I fail", "I'm unstable") + expect(MSpec).to receive(:read_tags).and_return([@t1, @t2]) + expect(MatchFilter).to receive(:new).with(nil, "I fail", "I'm unstable") TagPurgeAction.new.load end end -describe TagPurgeAction, "#after" do +RSpec.describe TagPurgeAction, "#after" do before :each do @state = double("ExampleState") - @state.stub(:description).and_return("str") + allow(@state).to receive(:description).and_return("str") @action = TagPurgeAction.new end it "does not save the description if the filter does not match" do - @action.should_receive(:===).with("str").and_return(false) + expect(@action).to receive(:===).with("str").and_return(false) @action.after @state - @action.matching.should == [] + expect(@action.matching).to eq([]) end it "saves the description if the filter matches" do - @action.should_receive(:===).with("str").and_return(true) + expect(@action).to receive(:===).with("str").and_return(true) @action.after @state - @action.matching.should == ["str"] + expect(@action.matching).to eq(["str"]) end end -describe TagPurgeAction, "#unload" do +RSpec.describe TagPurgeAction, "#unload" do before :each do @stdout = $stdout $stdout = IOStub.new @@ -64,11 +64,11 @@ describe TagPurgeAction, "#unload" do @t2 = SpecTag.new "unstable:I'm unstable" @t3 = SpecTag.new "fails:I'm unstable" - MSpec.stub(:read_tags).and_return([@t1, @t2, @t3]) - MSpec.stub(:write_tags) + allow(MSpec).to receive(:read_tags).and_return([@t1, @t2, @t3]) + allow(MSpec).to receive(:write_tags) @state = double("ExampleState") - @state.stub(:description).and_return("I'm unstable") + allow(@state).to receive(:description).and_return("I'm unstable") @action = TagPurgeAction.new @action.load @@ -80,37 +80,37 @@ describe TagPurgeAction, "#unload" do end it "does not rewrite any tags if there were no tags for the specs" do - MSpec.should_receive(:read_tags).and_return([]) - MSpec.should_receive(:delete_tags) - MSpec.should_not_receive(:write_tags) + expect(MSpec).to receive(:read_tags).and_return([]) + expect(MSpec).to receive(:delete_tags) + expect(MSpec).not_to receive(:write_tags) @action.load @action.after @state @action.unload - $stdout.should == "" + expect($stdout).to eq("") end it "rewrites tags that were matched" do - MSpec.should_receive(:write_tags).with([@t2, @t3]) + expect(MSpec).to receive(:write_tags).with([@t2, @t3]) @action.unload end it "prints tags that were not matched" do @action.unload - $stdout.should == "I fail\n" + expect($stdout).to eq("I fail\n") end end -describe TagPurgeAction, "#unload" do +RSpec.describe TagPurgeAction, "#unload" do before :each do @stdout = $stdout $stdout = IOStub.new - MSpec.stub(:read_tags).and_return([]) + allow(MSpec).to receive(:read_tags).and_return([]) @state = double("ExampleState") - @state.stub(:description).and_return("I'm unstable") + allow(@state).to receive(:description).and_return("I'm unstable") @action = TagPurgeAction.new @action.load @@ -122,33 +122,33 @@ describe TagPurgeAction, "#unload" do end it "deletes the tag file if no tags were found" do - MSpec.should_not_receive(:write_tags) - MSpec.should_receive(:delete_tags) + expect(MSpec).not_to receive(:write_tags) + expect(MSpec).to receive(:delete_tags) @action.unload - $stdout.should == "" + expect($stdout).to eq("") end end -describe TagPurgeAction, "#register" do +RSpec.describe TagPurgeAction, "#register" do before :each do - MSpec.stub(:register) + allow(MSpec).to receive(:register) @action = TagPurgeAction.new end it "registers itself with MSpec for the :unload event" do - MSpec.should_receive(:register).with(:unload, @action) + expect(MSpec).to receive(:register).with(:unload, @action) @action.register end end -describe TagPurgeAction, "#unregister" do +RSpec.describe TagPurgeAction, "#unregister" do before :each do - MSpec.stub(:unregister) + allow(MSpec).to receive(:unregister) @action = TagPurgeAction.new end it "unregisters itself with MSpec for the :unload event" do - MSpec.should_receive(:unregister).with(:unload, @action) + expect(MSpec).to receive(:unregister).with(:unload, @action) @action.unregister end end diff --git a/spec/mspec/spec/runner/actions/tally_spec.rb b/spec/mspec/spec/runner/actions/tally_spec.rb index be4635ffeb..d80ab1164a 100644 --- a/spec/mspec/spec/runner/actions/tally_spec.rb +++ b/spec/mspec/spec/runner/actions/tally_spec.rb @@ -4,169 +4,169 @@ require 'mspec/runner/actions/tally' require 'mspec/runner/mspec' require 'mspec/runner/example' -describe Tally, "#files!" do +RSpec.describe Tally, "#files!" do before :each do @tally = Tally.new end it "increments the count returned by #files" do @tally.files! 3 - @tally.files.should == 3 + expect(@tally.files).to eq(3) @tally.files! - @tally.files.should == 4 + expect(@tally.files).to eq(4) end end -describe Tally, "#examples!" do +RSpec.describe Tally, "#examples!" do before :each do @tally = Tally.new end it "increments the count returned by #examples" do @tally.examples! 2 - @tally.examples.should == 2 + expect(@tally.examples).to eq(2) @tally.examples! 2 - @tally.examples.should == 4 + expect(@tally.examples).to eq(4) end end -describe Tally, "#expectations!" do +RSpec.describe Tally, "#expectations!" do before :each do @tally = Tally.new end it "increments the count returned by #expectations" do @tally.expectations! - @tally.expectations.should == 1 + expect(@tally.expectations).to eq(1) @tally.expectations! 3 - @tally.expectations.should == 4 + expect(@tally.expectations).to eq(4) end end -describe Tally, "#failures!" do +RSpec.describe Tally, "#failures!" do before :each do @tally = Tally.new end it "increments the count returned by #failures" do @tally.failures! 1 - @tally.failures.should == 1 + expect(@tally.failures).to eq(1) @tally.failures! - @tally.failures.should == 2 + expect(@tally.failures).to eq(2) end end -describe Tally, "#errors!" do +RSpec.describe Tally, "#errors!" do before :each do @tally = Tally.new end it "increments the count returned by #errors" do @tally.errors! - @tally.errors.should == 1 + expect(@tally.errors).to eq(1) @tally.errors! 2 - @tally.errors.should == 3 + expect(@tally.errors).to eq(3) end end -describe Tally, "#guards!" do +RSpec.describe Tally, "#guards!" do before :each do @tally = Tally.new end it "increments the count returned by #guards" do @tally.guards! - @tally.guards.should == 1 + expect(@tally.guards).to eq(1) @tally.guards! 2 - @tally.guards.should == 3 + expect(@tally.guards).to eq(3) end end -describe Tally, "#file" do +RSpec.describe Tally, "#file" do before :each do @tally = Tally.new end it "returns a formatted string of the number of #files" do - @tally.file.should == "0 files" + expect(@tally.file).to eq("0 files") @tally.files! - @tally.file.should == "1 file" + expect(@tally.file).to eq("1 file") @tally.files! - @tally.file.should == "2 files" + expect(@tally.file).to eq("2 files") end end -describe Tally, "#example" do +RSpec.describe Tally, "#example" do before :each do @tally = Tally.new end it "returns a formatted string of the number of #examples" do - @tally.example.should == "0 examples" + expect(@tally.example).to eq("0 examples") @tally.examples! - @tally.example.should == "1 example" + expect(@tally.example).to eq("1 example") @tally.examples! - @tally.example.should == "2 examples" + expect(@tally.example).to eq("2 examples") end end -describe Tally, "#expectation" do +RSpec.describe Tally, "#expectation" do before :each do @tally = Tally.new end it "returns a formatted string of the number of #expectations" do - @tally.expectation.should == "0 expectations" + expect(@tally.expectation).to eq("0 expectations") @tally.expectations! - @tally.expectation.should == "1 expectation" + expect(@tally.expectation).to eq("1 expectation") @tally.expectations! - @tally.expectation.should == "2 expectations" + expect(@tally.expectation).to eq("2 expectations") end end -describe Tally, "#failure" do +RSpec.describe Tally, "#failure" do before :each do @tally = Tally.new end it "returns a formatted string of the number of #failures" do - @tally.failure.should == "0 failures" + expect(@tally.failure).to eq("0 failures") @tally.failures! - @tally.failure.should == "1 failure" + expect(@tally.failure).to eq("1 failure") @tally.failures! - @tally.failure.should == "2 failures" + expect(@tally.failure).to eq("2 failures") end end -describe Tally, "#error" do +RSpec.describe Tally, "#error" do before :each do @tally = Tally.new end it "returns a formatted string of the number of #errors" do - @tally.error.should == "0 errors" + expect(@tally.error).to eq("0 errors") @tally.errors! - @tally.error.should == "1 error" + expect(@tally.error).to eq("1 error") @tally.errors! - @tally.error.should == "2 errors" + expect(@tally.error).to eq("2 errors") end end -describe Tally, "#guard" do +RSpec.describe Tally, "#guard" do before :each do @tally = Tally.new end it "returns a formatted string of the number of #guards" do - @tally.guard.should == "0 guards" + expect(@tally.guard).to eq("0 guards") @tally.guards! - @tally.guard.should == "1 guard" + expect(@tally.guard).to eq("1 guard") @tally.guards! - @tally.guard.should == "2 guards" + expect(@tally.guard).to eq("2 guards") end end -describe Tally, "#format" do +RSpec.describe Tally, "#format" do before :each do @tally = Tally.new end @@ -181,7 +181,7 @@ describe Tally, "#format" do @tally.expectations! 4 @tally.errors! @tally.tagged! - @tally.format.should == "1 file, 2 examples, 4 expectations, 0 failures, 1 error, 1 tagged" + expect(@tally.format).to eq("1 file, 2 examples, 4 expectations, 0 failures, 1 error, 1 tagged") end it "includes guards if MSpec is in verify mode" do @@ -192,8 +192,9 @@ describe Tally, "#format" do @tally.errors! @tally.tagged! @tally.guards! - @tally.format.should == + expect(@tally.format).to eq( "1 file, 2 examples, 4 expectations, 0 failures, 1 error, 1 tagged, 1 guard" + ) end it "includes guards if MSpec is in report mode" do @@ -204,8 +205,9 @@ describe Tally, "#format" do @tally.errors! @tally.tagged! @tally.guards! 2 - @tally.format.should == + expect(@tally.format).to eq( "1 file, 2 examples, 4 expectations, 0 failures, 1 error, 1 tagged, 2 guards" + ) end it "includes guards if MSpec is in report_on mode" do @@ -215,23 +217,24 @@ describe Tally, "#format" do @tally.expectations! 4 @tally.errors! @tally.guards! 2 - @tally.format.should == + expect(@tally.format).to eq( "1 file, 2 examples, 4 expectations, 0 failures, 1 error, 0 tagged, 2 guards" + ) end end -describe TallyAction, "#counter" do +RSpec.describe TallyAction, "#counter" do before :each do @tally = TallyAction.new @state = ExampleState.new("describe", "it") end it "returns the Tally object" do - @tally.counter.should be_kind_of(Tally) + expect(@tally.counter).to be_kind_of(Tally) end end -describe TallyAction, "#load" do +RSpec.describe TallyAction, "#load" do before :each do @tally = TallyAction.new @state = ExampleState.new("describe", "it") @@ -239,11 +242,11 @@ describe TallyAction, "#load" do it "increments the count returned by Tally#files" do @tally.load - @tally.counter.files.should == 1 + expect(@tally.counter.files).to eq(1) end end -describe TallyAction, "#expectation" do +RSpec.describe TallyAction, "#expectation" do before :each do @tally = TallyAction.new @state = ExampleState.new("describe", "it") @@ -251,11 +254,11 @@ describe TallyAction, "#expectation" do it "increments the count returned by Tally#expectations" do @tally.expectation @state - @tally.counter.expectations.should == 1 + expect(@tally.counter.expectations).to eq(1) end end -describe TallyAction, "#example" do +RSpec.describe TallyAction, "#example" do before :each do @tally = TallyAction.new @state = ExampleState.new("describe", "it") @@ -263,14 +266,14 @@ describe TallyAction, "#example" do it "increments counts returned by Tally#examples" do @tally.example @state, nil - @tally.counter.examples.should == 1 - @tally.counter.expectations.should == 0 - @tally.counter.failures.should == 0 - @tally.counter.errors.should == 0 + expect(@tally.counter.examples).to eq(1) + expect(@tally.counter.expectations).to eq(0) + expect(@tally.counter.failures).to eq(0) + expect(@tally.counter.errors).to eq(0) end end -describe TallyAction, "#exception" do +RSpec.describe TallyAction, "#exception" do before :each do @tally = TallyAction.new @state = ExampleState.new("describe", "it") @@ -279,14 +282,14 @@ describe TallyAction, "#exception" do it "increments counts returned by Tally#failures" do exc = ExceptionState.new nil, nil, SpecExpectationNotMetError.new("Failed!") @tally.exception exc - @tally.counter.examples.should == 0 - @tally.counter.expectations.should == 0 - @tally.counter.failures.should == 1 - @tally.counter.errors.should == 0 + expect(@tally.counter.examples).to eq(0) + expect(@tally.counter.expectations).to eq(0) + expect(@tally.counter.failures).to eq(1) + expect(@tally.counter.errors).to eq(0) end end -describe TallyAction, "#exception" do +RSpec.describe TallyAction, "#exception" do before :each do @tally = TallyAction.new @state = ExampleState.new("describe", "it") @@ -295,14 +298,14 @@ describe TallyAction, "#exception" do it "increments counts returned by Tally#errors" do exc = ExceptionState.new nil, nil, Exception.new("Error!") @tally.exception exc - @tally.counter.examples.should == 0 - @tally.counter.expectations.should == 0 - @tally.counter.failures.should == 0 - @tally.counter.errors.should == 1 + expect(@tally.counter.examples).to eq(0) + expect(@tally.counter.expectations).to eq(0) + expect(@tally.counter.failures).to eq(0) + expect(@tally.counter.errors).to eq(1) end end -describe TallyAction, "#format" do +RSpec.describe TallyAction, "#format" do before :each do @tally = TallyAction.new @state = ExampleState.new("describe", "it") @@ -315,38 +318,38 @@ describe TallyAction, "#format" do @tally.expectation @state exc = ExceptionState.new nil, nil, SpecExpectationNotMetError.new("Failed!") @tally.exception exc - @tally.format.should == "1 file, 1 example, 2 expectations, 1 failure, 0 errors, 0 tagged" + expect(@tally.format).to eq("1 file, 1 example, 2 expectations, 1 failure, 0 errors, 0 tagged") end end -describe TallyAction, "#register" do +RSpec.describe TallyAction, "#register" do before :each do @tally = TallyAction.new @state = ExampleState.new("describe", "it") end it "registers itself with MSpec for appropriate actions" do - MSpec.should_receive(:register).with(:load, @tally) - MSpec.should_receive(:register).with(:exception, @tally) - MSpec.should_receive(:register).with(:example, @tally) - MSpec.should_receive(:register).with(:tagged, @tally) - MSpec.should_receive(:register).with(:expectation, @tally) + expect(MSpec).to receive(:register).with(:load, @tally) + expect(MSpec).to receive(:register).with(:exception, @tally) + expect(MSpec).to receive(:register).with(:example, @tally) + expect(MSpec).to receive(:register).with(:tagged, @tally) + expect(MSpec).to receive(:register).with(:expectation, @tally) @tally.register end end -describe TallyAction, "#unregister" do +RSpec.describe TallyAction, "#unregister" do before :each do @tally = TallyAction.new @state = ExampleState.new("describe", "it") end it "unregisters itself with MSpec for appropriate actions" do - MSpec.should_receive(:unregister).with(:load, @tally) - MSpec.should_receive(:unregister).with(:exception, @tally) - MSpec.should_receive(:unregister).with(:example, @tally) - MSpec.should_receive(:unregister).with(:tagged, @tally) - MSpec.should_receive(:unregister).with(:expectation, @tally) + expect(MSpec).to receive(:unregister).with(:load, @tally) + expect(MSpec).to receive(:unregister).with(:exception, @tally) + expect(MSpec).to receive(:unregister).with(:example, @tally) + expect(MSpec).to receive(:unregister).with(:tagged, @tally) + expect(MSpec).to receive(:unregister).with(:expectation, @tally) @tally.unregister end end diff --git a/spec/mspec/spec/runner/actions/timer_spec.rb b/spec/mspec/spec/runner/actions/timer_spec.rb index 417367d5a2..28a317177b 100644 --- a/spec/mspec/spec/runner/actions/timer_spec.rb +++ b/spec/mspec/spec/runner/actions/timer_spec.rb @@ -3,7 +3,7 @@ require 'mspec/runner/actions/timer' require 'mspec/runner/mspec' require 'time' -describe TimerAction do +RSpec.describe TimerAction do before :each do @timer = TimerAction.new @start_time = Time.utc(2009, 3, 30, 14, 5, 19) @@ -11,34 +11,34 @@ describe TimerAction do end it "responds to #start by recording the current time" do - Time.should_receive(:now) + expect(Time).to receive(:now) @timer.start end it "responds to #finish by recording the current time" do - Time.should_receive(:now) + expect(Time).to receive(:now) @timer.finish end it "responds to #elapsed by returning the difference between stop and start" do - Time.stub(:now).and_return(@start_time) + allow(Time).to receive(:now).and_return(@start_time) @timer.start - Time.stub(:now).and_return(@stop_time) + allow(Time).to receive(:now).and_return(@stop_time) @timer.finish - @timer.elapsed.should == 33 + expect(@timer.elapsed).to eq(33) end it "responds to #format by returning a readable string of elapsed time" do - Time.stub(:now).and_return(@start_time) + allow(Time).to receive(:now).and_return(@start_time) @timer.start - Time.stub(:now).and_return(@stop_time) + allow(Time).to receive(:now).and_return(@stop_time) @timer.finish - @timer.format.should == "Finished in 33.000000 seconds" + expect(@timer.format).to eq("Finished in 33.000000 seconds") end it "responds to #register by registering itself with MSpec for appropriate actions" do - MSpec.should_receive(:register).with(:start, @timer) - MSpec.should_receive(:register).with(:finish, @timer) + expect(MSpec).to receive(:register).with(:start, @timer) + expect(MSpec).to receive(:register).with(:finish, @timer) @timer.register end end 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 diff --git a/spec/mspec/spec/runner/example_spec.rb b/spec/mspec/spec/runner/example_spec.rb index 7d3ad6be30..8bac166da8 100644 --- a/spec/mspec/spec/runner/example_spec.rb +++ b/spec/mspec/spec/runner/example_spec.rb @@ -4,36 +4,36 @@ require 'mspec/runner/mspec' require 'mspec/mocks/mock' require 'mspec/runner/example' -describe ExampleState do +RSpec.describe ExampleState do it "is initialized with the ContextState, #it string, and #it block" do prc = lambda { } context = ContextState.new "" - ExampleState.new(context, "does", prc).should be_kind_of(ExampleState) + expect(ExampleState.new(context, "does", prc)).to be_kind_of(ExampleState) end end -describe ExampleState, "#describe" do +RSpec.describe ExampleState, "#describe" do before :each do @context = ContextState.new "Object#to_s" @state = ExampleState.new @context, "it" end it "returns the ContextState#description" do - @state.describe.should == @context.description + expect(@state.describe).to eq(@context.description) end end -describe ExampleState, "#it" do +RSpec.describe ExampleState, "#it" do before :each do @state = ExampleState.new ContextState.new("describe"), "it" end it "returns the argument to the #it block" do - @state.it.should == "it" + expect(@state.it).to eq("it") end end -describe ExampleState, "#context=" do +RSpec.describe ExampleState, "#context=" do before :each do @state = ExampleState.new ContextState.new("describe"), "it" @context = ContextState.new "New#context" @@ -41,28 +41,28 @@ describe ExampleState, "#context=" do it "sets the containing ContextState" do @state.context = @context - @state.context.should == @context + expect(@state.context).to eq(@context) end it "resets the description" do - @state.description.should == "describe it" + expect(@state.description).to eq("describe it") @state.context = @context - @state.description.should == "New#context it" + expect(@state.description).to eq("New#context it") end end -describe ExampleState, "#example" do +RSpec.describe ExampleState, "#example" do before :each do @proc = lambda { } @state = ExampleState.new ContextState.new("describe"), "it", @proc end it "returns the #it block" do - @state.example.should == @proc + expect(@state.example).to eq(@proc) end end -describe ExampleState, "#filtered?" do +RSpec.describe ExampleState, "#filtered?" do before :each do MSpec.store :include, [] MSpec.store :exclude, [] @@ -77,41 +77,41 @@ describe ExampleState, "#filtered?" do end it "returns false if MSpec include filters list is empty" do - @state.filtered?.should == false + expect(@state.filtered?).to eq(false) end it "returns false if MSpec include filters match this spec" do - @filter.should_receive(:===).and_return(true) + expect(@filter).to receive(:===).and_return(true) MSpec.register :include, @filter - @state.filtered?.should == false + expect(@state.filtered?).to eq(false) end it "returns true if MSpec include filters do not match this spec" do - @filter.should_receive(:===).and_return(false) + expect(@filter).to receive(:===).and_return(false) MSpec.register :include, @filter - @state.filtered?.should == true + expect(@state.filtered?).to eq(true) end it "returns false if MSpec exclude filters list is empty" do - @state.filtered?.should == false + expect(@state.filtered?).to eq(false) end it "returns false if MSpec exclude filters do not match this spec" do - @filter.should_receive(:===).and_return(false) + expect(@filter).to receive(:===).and_return(false) MSpec.register :exclude, @filter - @state.filtered?.should == false + expect(@state.filtered?).to eq(false) end it "returns true if MSpec exclude filters match this spec" do - @filter.should_receive(:===).and_return(true) + expect(@filter).to receive(:===).and_return(true) MSpec.register :exclude, @filter - @state.filtered?.should == true + expect(@state.filtered?).to eq(true) end it "returns true if MSpec include and exclude filters match this spec" do - @filter.should_receive(:===).twice.and_return(true) + expect(@filter).to receive(:===).twice.and_return(true) MSpec.register :include, @filter MSpec.register :exclude, @filter - @state.filtered?.should == true + expect(@state.filtered?).to eq(true) end end diff --git a/spec/mspec/spec/runner/exception_spec.rb b/spec/mspec/spec/runner/exception_spec.rb index 0e0a819992..a77a2c9cf4 100644 --- a/spec/mspec/spec/runner/exception_spec.rb +++ b/spec/mspec/spec/runner/exception_spec.rb @@ -4,16 +4,16 @@ require 'mspec/runner/example' require 'mspec/runner/exception' require 'mspec/utils/script' -describe ExceptionState, "#initialize" do +RSpec.describe ExceptionState, "#initialize" do it "takes a state, location (e.g. before :each), and exception" do context = ContextState.new "Class#method" state = ExampleState.new context, "does something" exc = Exception.new "Fail!" - ExceptionState.new(state, "location", exc).should be_kind_of(ExceptionState) + expect(ExceptionState.new(state, "location", exc)).to be_kind_of(ExceptionState) end end -describe ExceptionState, "#description" do +RSpec.describe ExceptionState, "#description" do before :each do context = ContextState.new "Class#method" @state = ExampleState.new context, "does something" @@ -21,99 +21,99 @@ describe ExceptionState, "#description" do it "returns the state description if state was not nil" do exc = ExceptionState.new(@state, nil, nil) - exc.description.should == "Class#method does something" + expect(exc.description).to eq("Class#method does something") end it "returns the location if it is not nil and description is nil" do exc = ExceptionState.new(nil, "location", nil) - exc.description.should == "An exception occurred during: location" + expect(exc.description).to eq("An exception occurred during: location") end it "returns both description and location if neither are nil" do exc = ExceptionState.new(@state, "location", nil) - exc.description.should == "An exception occurred during: location\nClass#method does something" + expect(exc.description).to eq("An exception occurred during: location\nClass#method does something") end end -describe ExceptionState, "#describe" do +RSpec.describe ExceptionState, "#describe" do before :each do context = ContextState.new "Class#method" @state = ExampleState.new context, "does something" end it "returns the ExampleState#describe string if created with a non-nil state" do - ExceptionState.new(@state, nil, nil).describe.should == @state.describe + expect(ExceptionState.new(@state, nil, nil).describe).to eq(@state.describe) end it "returns an empty string if created with a nil state" do - ExceptionState.new(nil, nil, nil).describe.should == "" + expect(ExceptionState.new(nil, nil, nil).describe).to eq("") end end -describe ExceptionState, "#it" do +RSpec.describe ExceptionState, "#it" do before :each do context = ContextState.new "Class#method" @state = ExampleState.new context, "does something" end it "returns the ExampleState#it string if created with a non-nil state" do - ExceptionState.new(@state, nil, nil).it.should == @state.it + expect(ExceptionState.new(@state, nil, nil).it).to eq(@state.it) end it "returns an empty string if created with a nil state" do - ExceptionState.new(nil, nil, nil).it.should == "" + expect(ExceptionState.new(nil, nil, nil).it).to eq("") end end -describe ExceptionState, "#failure?" do +RSpec.describe ExceptionState, "#failure?" do before :each do @state = ExampleState.new ContextState.new("C#m"), "works" end it "returns true if the exception is an SpecExpectationNotMetError" do exc = ExceptionState.new @state, "", SpecExpectationNotMetError.new("Fail!") - exc.failure?.should be_true + expect(exc.failure?).to be_truthy end it "returns true if the exception is an SpecExpectationNotFoundError" do exc = ExceptionState.new @state, "", SpecExpectationNotFoundError.new("Fail!") - exc.failure?.should be_true + expect(exc.failure?).to be_truthy end it "returns false if the exception is not an SpecExpectationNotMetError or an SpecExpectationNotFoundError" do exc = ExceptionState.new @state, "", Exception.new("Fail!") - exc.failure?.should be_false + expect(exc.failure?).to be_falsey end end -describe ExceptionState, "#message" do +RSpec.describe ExceptionState, "#message" do before :each do @state = ExampleState.new ContextState.new("C#m"), "works" end it "returns <No message> if the exception message is empty" do exc = ExceptionState.new @state, "", Exception.new("") - exc.message.should == "Exception: <No message>" + expect(exc.message).to eq("Exception: <No message>") end it "returns the message without exception class when the exception is an SpecExpectationNotMetError" do exc = ExceptionState.new @state, "", SpecExpectationNotMetError.new("Fail!") - exc.message.should == "Fail!" + expect(exc.message).to eq("Fail!") end it "returns SpecExpectationNotFoundError#message when the exception is an SpecExpectationNotFoundError" do e = SpecExpectationNotFoundError.new exc = ExceptionState.new @state, "", e - exc.message.should == e.message + expect(exc.message).to eq(e.message) end it "returns the message with exception class when the exception is not an SpecExpectationNotMetError or an SpecExpectationNotFoundError" do exc = ExceptionState.new @state, "", Exception.new("Fail!") - exc.message.should == "Exception: Fail!" + expect(exc.message).to eq("Exception: Fail!") end end -describe ExceptionState, "#backtrace" do +RSpec.describe ExceptionState, "#backtrace" do before :each do @state = ExampleState.new ContextState.new("C#m"), "works" begin @@ -128,19 +128,19 @@ describe ExceptionState, "#backtrace" do end it "returns a string representation of the exception backtrace" do - @exc.backtrace.should be_kind_of(String) + expect(@exc.backtrace).to be_kind_of(String) end it "does not filter files from the backtrace if $MSPEC_DEBUG is true" do $MSPEC_DEBUG = true - @exc.backtrace.should == @exception.backtrace.join("\n") + expect(@exc.backtrace).to eq(@exception.backtrace.join("\n")) end it "filters files matching config[:backtrace_filter]" do MSpecScript.set :backtrace_filter, %r[mspec/lib] $MSPEC_DEBUG = nil @exc.backtrace.split("\n").each do |line| - line.should_not =~ %r[mspec/lib] + expect(line).not_to match(%r[mspec/lib]) end end end diff --git a/spec/mspec/spec/runner/filters/match_spec.rb b/spec/mspec/spec/runner/filters/match_spec.rb index f2c665c495..970da00446 100644 --- a/spec/mspec/spec/runner/filters/match_spec.rb +++ b/spec/mspec/spec/runner/filters/match_spec.rb @@ -2,33 +2,33 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'mspec/runner/mspec' require 'mspec/runner/filters/match' -describe MatchFilter, "#===" do +RSpec.describe MatchFilter, "#===" do before :each do @filter = MatchFilter.new nil, 'a', 'b', 'c' end it "returns true if the argument matches any of the #initialize strings" do - @filter.===('aaa').should == true - @filter.===('bccb').should == true + expect(@filter.===('aaa')).to eq(true) + expect(@filter.===('bccb')).to eq(true) end it "returns false if the argument matches none of the #initialize strings" do - @filter.===('d').should == false + expect(@filter.===('d')).to eq(false) end end -describe MatchFilter, "#register" do +RSpec.describe MatchFilter, "#register" do it "registers itself with MSpec for the designated action list" do filter = MatchFilter.new :include - MSpec.should_receive(:register).with(:include, filter) + expect(MSpec).to receive(:register).with(:include, filter) filter.register end end -describe MatchFilter, "#unregister" do +RSpec.describe MatchFilter, "#unregister" do it "unregisters itself with MSpec for the designated action list" do filter = MatchFilter.new :exclude - MSpec.should_receive(:unregister).with(:exclude, filter) + expect(MSpec).to receive(:unregister).with(:exclude, filter) filter.unregister end end diff --git a/spec/mspec/spec/runner/filters/profile_spec.rb b/spec/mspec/spec/runner/filters/profile_spec.rb index 89d0ad1911..25f5e07aef 100644 --- a/spec/mspec/spec/runner/filters/profile_spec.rb +++ b/spec/mspec/spec/runner/filters/profile_spec.rb @@ -2,45 +2,45 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'mspec/runner/mspec' require 'mspec/runner/filters/profile' -describe ProfileFilter, "#find" do +RSpec.describe ProfileFilter, "#find" do before :each do @filter = ProfileFilter.new nil - File.stub(:exist?).and_return(false) + allow(File).to receive(:exist?).and_return(false) @file = "rails.yaml" end it "attempts to locate the file through the expanded path name" do - File.should_receive(:expand_path).with(@file).and_return(@file) - File.should_receive(:exist?).with(@file).and_return(true) - @filter.find(@file).should == @file + expect(File).to receive(:expand_path).with(@file).and_return(@file) + expect(File).to receive(:exist?).with(@file).and_return(true) + expect(@filter.find(@file)).to eq(@file) end it "attempts to locate the file in 'spec/profiles'" do path = File.join "spec/profiles", @file - File.should_receive(:exist?).with(path).and_return(true) - @filter.find(@file).should == path + expect(File).to receive(:exist?).with(path).and_return(true) + expect(@filter.find(@file)).to eq(path) end it "attempts to locate the file in 'spec'" do path = File.join "spec", @file - File.should_receive(:exist?).with(path).and_return(true) - @filter.find(@file).should == path + expect(File).to receive(:exist?).with(path).and_return(true) + expect(@filter.find(@file)).to eq(path) end it "attempts to locate the file in 'profiles'" do path = File.join "profiles", @file - File.should_receive(:exist?).with(path).and_return(true) - @filter.find(@file).should == path + expect(File).to receive(:exist?).with(path).and_return(true) + expect(@filter.find(@file)).to eq(path) end it "attempts to locate the file in '.'" do path = File.join ".", @file - File.should_receive(:exist?).with(path).and_return(true) - @filter.find(@file).should == path + expect(File).to receive(:exist?).with(path).and_return(true) + expect(@filter.find(@file)).to eq(path) end end -describe ProfileFilter, "#parse" do +RSpec.describe ProfileFilter, "#parse" do before :each do @filter = ProfileFilter.new nil @file = File.open(File.dirname(__FILE__) + "/b.yaml", "r") @@ -51,14 +51,14 @@ describe ProfileFilter, "#parse" do end it "creates a Hash of the contents of the YAML file" do - @filter.parse(@file).should == { + expect(@filter.parse(@file)).to eq({ "B." => ["b", "bb"], "B::C#" => ["b!", "b=", "b?", "-", "[]", "[]="] - } + }) end end -describe ProfileFilter, "#load" do +RSpec.describe ProfileFilter, "#load" do before :each do @filter = ProfileFilter.new nil @files = [ @@ -68,50 +68,50 @@ describe ProfileFilter, "#load" do end it "generates a composite hash from multiple YAML files" do - @filter.load(*@files).should == { + expect(@filter.load(*@files)).to eq({ "A#" => ["a", "aa"], "B." => ["b", "bb"], "B::C#" => ["b!", "b=", "b?", "-", "[]", "[]="] - } + }) end end -describe ProfileFilter, "#===" do +RSpec.describe ProfileFilter, "#===" do before :each do @filter = ProfileFilter.new nil - @filter.stub(:load).and_return({ "A#" => ["[]=", "a", "a!", "a?", "aa="]}) + allow(@filter).to receive(:load).and_return({ "A#" => ["[]=", "a", "a!", "a?", "aa="]}) @filter.send :initialize, nil end it "returns true if the spec description is for a method in the profile" do - @filter.===("The A#[]= method").should == true - @filter.===("A#a returns").should == true - @filter.===("A#a! replaces").should == true - @filter.===("A#a? returns").should == true - @filter.===("A#aa= raises").should == true + expect(@filter.===("The A#[]= method")).to eq(true) + expect(@filter.===("A#a returns")).to eq(true) + expect(@filter.===("A#a! replaces")).to eq(true) + expect(@filter.===("A#a? returns")).to eq(true) + expect(@filter.===("A#aa= raises")).to eq(true) end it "returns false if the spec description is for a method not in the profile" do - @filter.===("The A#[] method").should == false - @filter.===("B#a returns").should == false - @filter.===("A.a! replaces").should == false - @filter.===("AA#a? returns").should == false - @filter.===("A#aa raises").should == false + expect(@filter.===("The A#[] method")).to eq(false) + expect(@filter.===("B#a returns")).to eq(false) + expect(@filter.===("A.a! replaces")).to eq(false) + expect(@filter.===("AA#a? returns")).to eq(false) + expect(@filter.===("A#aa raises")).to eq(false) end end -describe ProfileFilter, "#register" do +RSpec.describe ProfileFilter, "#register" do it "registers itself with MSpec for the designated action list" do filter = ProfileFilter.new :include - MSpec.should_receive(:register).with(:include, filter) + expect(MSpec).to receive(:register).with(:include, filter) filter.register end end -describe ProfileFilter, "#unregister" do +RSpec.describe ProfileFilter, "#unregister" do it "unregisters itself with MSpec for the designated action list" do filter = ProfileFilter.new :exclude - MSpec.should_receive(:unregister).with(:exclude, filter) + expect(MSpec).to receive(:unregister).with(:exclude, filter) filter.unregister end end diff --git a/spec/mspec/spec/runner/filters/regexp_spec.rb b/spec/mspec/spec/runner/filters/regexp_spec.rb index 8e9b0ec7e8..1d1d3554f6 100644 --- a/spec/mspec/spec/runner/filters/regexp_spec.rb +++ b/spec/mspec/spec/runner/filters/regexp_spec.rb @@ -2,30 +2,30 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'mspec/runner/mspec' require 'mspec/runner/filters/regexp' -describe MatchFilter, "#===" do +RSpec.describe MatchFilter, "#===" do before :each do @filter = RegexpFilter.new nil, 'a(b|c)', 'b[^ab]', 'cc?' end it "returns true if the argument matches any of the #initialize strings" do - @filter.===('ab').should == true - @filter.===('bc suffix').should == true - @filter.===('prefix cc').should == true + expect(@filter.===('ab')).to eq(true) + expect(@filter.===('bc suffix')).to eq(true) + expect(@filter.===('prefix cc')).to eq(true) end it "returns false if the argument matches none of the #initialize strings" do - @filter.===('aa').should == false - @filter.===('ba').should == false - @filter.===('prefix d suffix').should == false + expect(@filter.===('aa')).to eq(false) + expect(@filter.===('ba')).to eq(false) + expect(@filter.===('prefix d suffix')).to eq(false) end end -describe RegexpFilter, "#to_regexp" do +RSpec.describe RegexpFilter, "#to_regexp" do before :each do @filter = RegexpFilter.new nil end it "converts its arguments to Regexp instances" do - @filter.send(:to_regexp, 'a(b|c)', 'b[^ab]', 'cc?').should == [/a(b|c)/, /b[^ab]/, /cc?/] + expect(@filter.send(:to_regexp, 'a(b|c)', 'b[^ab]', 'cc?')).to eq([/a(b|c)/, /b[^ab]/, /cc?/]) end end diff --git a/spec/mspec/spec/runner/filters/tag_spec.rb b/spec/mspec/spec/runner/filters/tag_spec.rb index fe1f3df039..356175a754 100644 --- a/spec/mspec/spec/runner/filters/tag_spec.rb +++ b/spec/mspec/spec/runner/filters/tag_spec.rb @@ -3,90 +3,90 @@ require 'mspec/runner/mspec' require 'mspec/runner/filters/match' require 'mspec/runner/filters/tag' -describe TagFilter, "#load" do +RSpec.describe TagFilter, "#load" do before :each do @match = double("match filter").as_null_object @filter = TagFilter.new :include, "tag", "key" @tag = SpecTag.new "tag(comment):description" - MSpec.stub(:read_tags).and_return([@tag]) - MSpec.stub(:register) + allow(MSpec).to receive(:read_tags).and_return([@tag]) + allow(MSpec).to receive(:register) end it "loads tags from the tag file" do - MSpec.should_receive(:read_tags).with(["tag", "key"]).and_return([]) + expect(MSpec).to receive(:read_tags).with(["tag", "key"]).and_return([]) @filter.load end it "registers itself with MSpec for the :include action" do filter = TagFilter.new(:include) - MSpec.should_receive(:register).with(:include, filter) + expect(MSpec).to receive(:register).with(:include, filter) filter.load end it "registers itself with MSpec for the :exclude action" do filter = TagFilter.new(:exclude) - MSpec.should_receive(:register).with(:exclude, filter) + expect(MSpec).to receive(:register).with(:exclude, filter) filter.load end end -describe TagFilter, "#unload" do +RSpec.describe TagFilter, "#unload" do before :each do @filter = TagFilter.new :include, "tag", "key" @tag = SpecTag.new "tag(comment):description" - MSpec.stub(:read_tags).and_return([@tag]) - MSpec.stub(:register) + allow(MSpec).to receive(:read_tags).and_return([@tag]) + allow(MSpec).to receive(:register) end it "unregisters itself" do @filter.load - MSpec.should_receive(:unregister).with(:include, @filter) + expect(MSpec).to receive(:unregister).with(:include, @filter) @filter.unload end end -describe TagFilter, "#register" do +RSpec.describe TagFilter, "#register" do before :each do - MSpec.stub(:register) + allow(MSpec).to receive(:register) end it "registers itself with MSpec for the :load, :unload actions" do filter = TagFilter.new(nil) - MSpec.should_receive(:register).with(:load, filter) - MSpec.should_receive(:register).with(:unload, filter) + expect(MSpec).to receive(:register).with(:load, filter) + expect(MSpec).to receive(:register).with(:unload, filter) filter.register end end -describe TagFilter, "#unregister" do +RSpec.describe TagFilter, "#unregister" do before :each do - MSpec.stub(:unregister) + allow(MSpec).to receive(:unregister) end it "unregisters itself with MSpec for the :load, :unload actions" do filter = TagFilter.new(nil) - MSpec.should_receive(:unregister).with(:load, filter) - MSpec.should_receive(:unregister).with(:unload, filter) + expect(MSpec).to receive(:unregister).with(:load, filter) + expect(MSpec).to receive(:unregister).with(:unload, filter) filter.unregister end end -describe TagFilter, "#===" do +RSpec.describe TagFilter, "#===" do before :each do @filter = TagFilter.new nil, "tag", "key" @tag = SpecTag.new "tag(comment):description" - MSpec.stub(:read_tags).and_return([@tag]) - MSpec.stub(:register) + allow(MSpec).to receive(:read_tags).and_return([@tag]) + allow(MSpec).to receive(:register) @filter.load end it "returns true if the argument matches any of the descriptions" do - @filter.===('description').should == true + expect(@filter.===('description')).to eq(true) end it "returns false if the argument matches none of the descriptions" do - @filter.===('descriptionA').should == false - @filter.===('adescription').should == false + expect(@filter.===('descriptionA')).to eq(false) + expect(@filter.===('adescription')).to eq(false) end end diff --git a/spec/mspec/spec/runner/formatters/describe_spec.rb b/spec/mspec/spec/runner/formatters/describe_spec.rb index 415ced71fb..55f497aca6 100644 --- a/spec/mspec/spec/runner/formatters/describe_spec.rb +++ b/spec/mspec/spec/runner/formatters/describe_spec.rb @@ -2,14 +2,14 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'mspec/runner/formatters/describe' require 'mspec/runner/example' -describe DescribeFormatter, "#finish" do +RSpec.describe DescribeFormatter, "#finish" do before :each do - MSpec.stub(:register) - MSpec.stub(:unregister) + allow(MSpec).to receive(:register) + allow(MSpec).to receive(:unregister) @timer = double("timer").as_null_object - TimerAction.stub(:new).and_return(@timer) - @timer.stub(:format).and_return("Finished in 2.0 seconds") + allow(TimerAction).to receive(:new).and_return(@timer) + allow(@timer).to receive(:format).and_return("Finished in 2.0 seconds") $stdout = @out = IOStub.new context = ContextState.new "Class#method" @@ -32,36 +32,36 @@ describe DescribeFormatter, "#finish" do it "prints a summary of elapsed time" do @formatter.finish - @out.should =~ /^Finished in 2.0 seconds$/ + expect(@out).to match(/^Finished in 2.0 seconds$/) end it "prints a tally of counts" do @formatter.finish - @out.should =~ /^1 file, 1 example, 2 expectations, 0 failures, 0 errors, 0 tagged$/ + expect(@out).to match(/^1 file, 1 example, 2 expectations, 0 failures, 0 errors, 0 tagged$/) end it "does not print exceptions" do @formatter.finish - @out.should == %[ + expect(@out).to eq(%[ Finished in 2.0 seconds 1 file, 1 example, 2 expectations, 0 failures, 0 errors, 0 tagged -] +]) end it "prints a summary of failures and errors for each describe block" do exc = ExceptionState.new @state, nil, MSpecExampleError.new("broken") - exc.stub(:backtrace).and_return("path/to/some/file.rb:35:in method") + allow(exc).to receive(:backtrace).and_return("path/to/some/file.rb:35:in method") @formatter.exception exc @formatter.finish - @out.should == %[ + expect(@out).to eq(%[ Class#method 0 failures, 1 error Finished in 2.0 seconds 1 file, 1 example, 2 expectations, 0 failures, 0 errors, 0 tagged -] +]) end end diff --git a/spec/mspec/spec/runner/formatters/dotted_spec.rb b/spec/mspec/spec/runner/formatters/dotted_spec.rb index 5af2ff55f8..336b1227ed 100644 --- a/spec/mspec/spec/runner/formatters/dotted_spec.rb +++ b/spec/mspec/spec/runner/formatters/dotted_spec.rb @@ -4,7 +4,7 @@ require 'mspec/runner/mspec' require 'mspec/runner/example' require 'mspec/utils/script' -describe DottedFormatter, "#initialize" do +RSpec.describe DottedFormatter, "#initialize" do it "permits zero arguments" do DottedFormatter.new end @@ -14,33 +14,33 @@ describe DottedFormatter, "#initialize" do end end -describe DottedFormatter, "#register" do +RSpec.describe DottedFormatter, "#register" do before :each do @formatter = DottedFormatter.new - MSpec.stub(:register) + allow(MSpec).to receive(:register) end it "registers self with MSpec for appropriate actions" do - MSpec.should_receive(:register).with(:exception, @formatter) - MSpec.should_receive(:register).with(:before, @formatter) - MSpec.should_receive(:register).with(:after, @formatter) - MSpec.should_receive(:register).with(:finish, @formatter) + expect(MSpec).to receive(:register).with(:exception, @formatter) + expect(MSpec).to receive(:register).with(:before, @formatter) + expect(MSpec).to receive(:register).with(:after, @formatter) + expect(MSpec).to receive(:register).with(:finish, @formatter) @formatter.register end it "creates TimerAction and TallyAction" do timer = double("timer") tally = double("tally") - timer.should_receive(:register) - tally.should_receive(:register) - tally.should_receive(:counter) - TimerAction.should_receive(:new).and_return(timer) - TallyAction.should_receive(:new).and_return(tally) + expect(timer).to receive(:register) + expect(tally).to receive(:register) + expect(tally).to receive(:counter) + expect(TimerAction).to receive(:new).and_return(timer) + expect(TallyAction).to receive(:new).and_return(tally) @formatter.register end end -describe DottedFormatter, "#print" do +RSpec.describe DottedFormatter, "#print" do before :each do $stdout = IOStub.new end @@ -52,25 +52,25 @@ describe DottedFormatter, "#print" do it "writes to $stdout by default" do formatter = DottedFormatter.new formatter.print "begonias" - $stdout.should == "begonias" + expect($stdout).to eq("begonias") end it "writes to the file specified when the formatter was created" do out = IOStub.new - File.should_receive(:open).with("some/file", "w").and_return(out) + expect(File).to receive(:open).with("some/file", "w").and_return(out) formatter = DottedFormatter.new "some/file" formatter.print "begonias" - out.should == "begonias" + expect(out).to eq("begonias") end it "flushes the IO output" do - $stdout.should_receive(:flush) + expect($stdout).to receive(:flush) formatter = DottedFormatter.new formatter.print "begonias" end end -describe DottedFormatter, "#exception" do +RSpec.describe DottedFormatter, "#exception" do before :each do @formatter = DottedFormatter.new @failure = ExceptionState.new nil, nil, SpecExpectationNotMetError.new("failed") @@ -79,27 +79,27 @@ describe DottedFormatter, "#exception" do it "sets the #failure? flag" do @formatter.exception @failure - @formatter.failure?.should be_true + expect(@formatter.failure?).to be_truthy @formatter.exception @error - @formatter.failure?.should be_false + expect(@formatter.failure?).to be_falsey end it "sets the #exception? flag" do @formatter.exception @error - @formatter.exception?.should be_true + expect(@formatter.exception?).to be_truthy @formatter.exception @failure - @formatter.exception?.should be_true + expect(@formatter.exception?).to be_truthy end it "adds the exception to the list of exceptions" do - @formatter.exceptions.should == [] + expect(@formatter.exceptions).to eq([]) @formatter.exception @error @formatter.exception @failure - @formatter.exceptions.should == [@error, @failure] + expect(@formatter.exceptions).to eq([@error, @failure]) end end -describe DottedFormatter, "#exception?" do +RSpec.describe DottedFormatter, "#exception?" do before :each do @formatter = DottedFormatter.new @failure = ExceptionState.new nil, nil, SpecExpectationNotMetError.new("failed") @@ -107,29 +107,29 @@ describe DottedFormatter, "#exception?" do end it "returns false if there have been no exceptions" do - @formatter.exception?.should be_false + expect(@formatter.exception?).to be_falsey end it "returns true if any exceptions are errors" do @formatter.exception @failure @formatter.exception @error - @formatter.exception?.should be_true + expect(@formatter.exception?).to be_truthy end it "returns true if all exceptions are failures" do @formatter.exception @failure @formatter.exception @failure - @formatter.exception?.should be_true + expect(@formatter.exception?).to be_truthy end it "returns true if all exceptions are errors" do @formatter.exception @error @formatter.exception @error - @formatter.exception?.should be_true + expect(@formatter.exception?).to be_truthy end end -describe DottedFormatter, "#failure?" do +RSpec.describe DottedFormatter, "#failure?" do before :each do @formatter = DottedFormatter.new @failure = ExceptionState.new nil, nil, SpecExpectationNotMetError.new("failed") @@ -137,23 +137,23 @@ describe DottedFormatter, "#failure?" do end it "returns false if there have been no exceptions" do - @formatter.failure?.should be_false + expect(@formatter.failure?).to be_falsey end it "returns false if any exceptions are errors" do @formatter.exception @failure @formatter.exception @error - @formatter.failure?.should be_false + expect(@formatter.failure?).to be_falsey end it "returns true if all exceptions are failures" do @formatter.exception @failure @formatter.exception @failure - @formatter.failure?.should be_true + expect(@formatter.failure?).to be_truthy end end -describe DottedFormatter, "#before" do +RSpec.describe DottedFormatter, "#before" do before :each do @state = ExampleState.new ContextState.new("describe"), "it" @formatter = DottedFormatter.new @@ -161,19 +161,19 @@ describe DottedFormatter, "#before" do end it "resets the #failure? flag to false" do - @formatter.failure?.should be_true + expect(@formatter.failure?).to be_truthy @formatter.before @state - @formatter.failure?.should be_false + expect(@formatter.failure?).to be_falsey end it "resets the #exception? flag to false" do - @formatter.exception?.should be_true + expect(@formatter.exception?).to be_truthy @formatter.before @state - @formatter.exception?.should be_false + expect(@formatter.exception?).to be_falsey end end -describe DottedFormatter, "#after" do +RSpec.describe DottedFormatter, "#after" do before :each do $stdout = @out = IOStub.new @formatter = DottedFormatter.new @@ -186,21 +186,21 @@ describe DottedFormatter, "#after" do it "prints a '.' if there was no exception raised" do @formatter.after(@state) - @out.should == "." + expect(@out).to eq(".") end it "prints an 'F' if there was an expectation failure" do exc = SpecExpectationNotMetError.new "failed" @formatter.exception ExceptionState.new(@state, nil, exc) @formatter.after(@state) - @out.should == "F" + expect(@out).to eq("F") end it "prints an 'E' if there was an exception other than expectation failure" do exc = MSpecExampleError.new("boom!") @formatter.exception ExceptionState.new(@state, nil, exc) @formatter.after(@state) - @out.should == "E" + expect(@out).to eq("E") end it "prints an 'E' if there are mixed exceptions and exepctation failures" do @@ -209,21 +209,21 @@ describe DottedFormatter, "#after" do exc = MSpecExampleError.new("boom!") @formatter.exception ExceptionState.new(@state, nil, exc) @formatter.after(@state) - @out.should == "E" + expect(@out).to eq("E") end end -describe DottedFormatter, "#finish" do +RSpec.describe DottedFormatter, "#finish" do before :each do @tally = double("tally").as_null_object - TallyAction.stub(:new).and_return(@tally) + allow(TallyAction).to receive(:new).and_return(@tally) @timer = double("timer").as_null_object - TimerAction.stub(:new).and_return(@timer) + allow(TimerAction).to receive(:new).and_return(@timer) $stdout = @out = IOStub.new context = ContextState.new "Class#method" @state = ExampleState.new(context, "runs") - MSpec.stub(:register) + allow(MSpec).to receive(:register) @formatter = DottedFormatter.new @formatter.register end @@ -237,40 +237,39 @@ describe DottedFormatter, "#finish" do @formatter.exception exc @formatter.after @state @formatter.finish - @out.should =~ /^1\)\nClass#method runs ERROR$/ + expect(@out).to match(/^1\)\nClass#method runs ERROR$/) end it "prints a backtrace for an exception" do exc = ExceptionState.new @state, nil, MSpecExampleError.new("broken") - exc.stub(:backtrace).and_return("path/to/some/file.rb:35:in method") + allow(exc).to receive(:backtrace).and_return("path/to/some/file.rb:35:in method") @formatter.exception exc @formatter.after @state @formatter.finish - @out.should =~ %r[path/to/some/file.rb:35:in method$] + expect(@out).to match(%r[path/to/some/file.rb:35:in method$]) end it "prints a summary of elapsed time" do - @timer.should_receive(:format).and_return("Finished in 2.0 seconds") + expect(@timer).to receive(:format).and_return("Finished in 2.0 seconds") @formatter.finish - @out.should =~ /^Finished in 2.0 seconds$/ + expect(@out).to match(/^Finished in 2.0 seconds$/) end it "prints a tally of counts" do - @tally.should_receive(:format).and_return("1 example, 0 failures") + expect(@tally).to receive(:format).and_return("1 example, 0 failures") @formatter.finish - @out.should =~ /^1 example, 0 failures$/ + expect(@out).to match(/^1 example, 0 failures$/) end it "prints errors, backtraces, elapsed time, and tallies" do exc = ExceptionState.new @state, nil, MSpecExampleError.new("broken") - exc.stub(:backtrace).and_return("path/to/some/file.rb:35:in method") + allow(exc).to receive(:backtrace).and_return("path/to/some/file.rb:35:in method") @formatter.exception exc - @timer.should_receive(:format).and_return("Finished in 2.0 seconds") - @tally.should_receive(:format).and_return("1 example, 1 failure") + expect(@timer).to receive(:format).and_return("Finished in 2.0 seconds") + expect(@tally).to receive(:format).and_return("1 example, 1 failure") @formatter.after @state @formatter.finish - @out.should == -%[E + expect(@out).to eq(%[E 1) Class#method runs ERROR @@ -280,6 +279,6 @@ path/to/some/file.rb:35:in method Finished in 2.0 seconds 1 example, 1 failure -] +]) end end diff --git a/spec/mspec/spec/runner/formatters/file_spec.rb b/spec/mspec/spec/runner/formatters/file_spec.rb index 946683ad58..ae11d60845 100644 --- a/spec/mspec/spec/runner/formatters/file_spec.rb +++ b/spec/mspec/spec/runner/formatters/file_spec.rb @@ -3,27 +3,27 @@ require 'mspec/runner/formatters/file' require 'mspec/runner/mspec' require 'mspec/runner/example' -describe FileFormatter, "#register" do +RSpec.describe FileFormatter, "#register" do before :each do @formatter = FileFormatter.new - MSpec.stub(:register) - MSpec.stub(:unregister) + allow(MSpec).to receive(:register) + allow(MSpec).to receive(:unregister) end it "registers self with MSpec for :load, :unload actions" do - MSpec.should_receive(:register).with(:load, @formatter) - MSpec.should_receive(:register).with(:unload, @formatter) + expect(MSpec).to receive(:register).with(:load, @formatter) + expect(MSpec).to receive(:register).with(:unload, @formatter) @formatter.register end it "unregisters self with MSpec for :before, :after actions" do - MSpec.should_receive(:unregister).with(:before, @formatter) - MSpec.should_receive(:unregister).with(:after, @formatter) + expect(MSpec).to receive(:unregister).with(:before, @formatter) + expect(MSpec).to receive(:unregister).with(:after, @formatter) @formatter.register end end -describe FileFormatter, "#load" do +RSpec.describe FileFormatter, "#load" do before :each do @state = ExampleState.new ContextState.new("describe"), "it" @formatter = FileFormatter.new @@ -31,19 +31,19 @@ describe FileFormatter, "#load" do end it "resets the #failure? flag to false" do - @formatter.failure?.should be_true + expect(@formatter.failure?).to be_truthy @formatter.load @state - @formatter.failure?.should be_false + expect(@formatter.failure?).to be_falsey end it "resets the #exception? flag to false" do - @formatter.exception?.should be_true + expect(@formatter.exception?).to be_truthy @formatter.load @state - @formatter.exception?.should be_false + expect(@formatter.exception?).to be_falsey end end -describe FileFormatter, "#unload" do +RSpec.describe FileFormatter, "#unload" do before :each do $stdout = @out = IOStub.new @formatter = FileFormatter.new @@ -56,21 +56,21 @@ describe FileFormatter, "#unload" do it "prints a '.' if there was no exception raised" do @formatter.unload(@state) - @out.should == "." + expect(@out).to eq(".") end it "prints an 'F' if there was an expectation failure" do exc = SpecExpectationNotMetError.new "failed" @formatter.exception ExceptionState.new(@state, nil, exc) @formatter.unload(@state) - @out.should == "F" + expect(@out).to eq("F") end it "prints an 'E' if there was an exception other than expectation failure" do exc = MSpecExampleError.new("boom!") @formatter.exception ExceptionState.new(@state, nil, exc) @formatter.unload(@state) - @out.should == "E" + expect(@out).to eq("E") end it "prints an 'E' if there are mixed exceptions and exepctation failures" do @@ -79,6 +79,6 @@ describe FileFormatter, "#unload" do exc = MSpecExampleError.new("boom!") @formatter.exception ExceptionState.new(@state, nil, exc) @formatter.unload(@state) - @out.should == "E" + expect(@out).to eq("E") end end diff --git a/spec/mspec/spec/runner/formatters/html_spec.rb b/spec/mspec/spec/runner/formatters/html_spec.rb index 3783ab6a89..ed973ad93f 100644 --- a/spec/mspec/spec/runner/formatters/html_spec.rb +++ b/spec/mspec/spec/runner/formatters/html_spec.rb @@ -4,22 +4,23 @@ require 'mspec/runner/formatters/html' require 'mspec/runner/mspec' require 'mspec/runner/example' require 'mspec/utils/script' +require 'mspec/helpers' -describe HtmlFormatter do +RSpec.describe HtmlFormatter do before :each do @formatter = HtmlFormatter.new end it "responds to #register by registering itself with MSpec for appropriate actions" do - MSpec.stub(:register) - MSpec.should_receive(:register).with(:start, @formatter) - MSpec.should_receive(:register).with(:enter, @formatter) - MSpec.should_receive(:register).with(:leave, @formatter) + allow(MSpec).to receive(:register) + expect(MSpec).to receive(:register).with(:start, @formatter) + expect(MSpec).to receive(:register).with(:enter, @formatter) + expect(MSpec).to receive(:register).with(:leave, @formatter) @formatter.register end end -describe HtmlFormatter, "#start" do +RSpec.describe HtmlFormatter, "#start" do before :each do $stdout = @out = IOStub.new @formatter = HtmlFormatter.new @@ -32,9 +33,8 @@ describe HtmlFormatter, "#start" do it "prints the HTML head" do @formatter.start ruby_engine = RUBY_ENGINE - ruby_engine.should =~ /^#{ruby_engine}/ - @out.should == -%[<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" + expect(ruby_engine).to match(/^#{ruby_engine}/) + expect(@out).to eq(%[<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> @@ -55,11 +55,11 @@ ul { </style> </head> <body> -] +]) end end -describe HtmlFormatter, "#enter" do +RSpec.describe HtmlFormatter, "#enter" do before :each do $stdout = @out = IOStub.new @formatter = HtmlFormatter.new @@ -71,11 +71,11 @@ describe HtmlFormatter, "#enter" do it "prints the #describe string" do @formatter.enter "describe" - @out.should == "<div><p>describe</p>\n<ul>\n" + expect(@out).to eq("<div><p>describe</p>\n<ul>\n") end end -describe HtmlFormatter, "#leave" do +RSpec.describe HtmlFormatter, "#leave" do before :each do $stdout = @out = IOStub.new @formatter = HtmlFormatter.new @@ -87,11 +87,11 @@ describe HtmlFormatter, "#leave" do it "prints the closing tags for the #describe string" do @formatter.leave - @out.should == "</ul>\n</div>\n" + expect(@out).to eq("</ul>\n</div>\n") end end -describe HtmlFormatter, "#exception" do +RSpec.describe HtmlFormatter, "#exception" do before :each do $stdout = @out = IOStub.new @formatter = HtmlFormatter.new @@ -108,14 +108,13 @@ describe HtmlFormatter, "#exception" do @formatter.exception exc exc = ExceptionState.new @state, nil, MSpecExampleError.new("painful") @formatter.exception exc - @out.should == -%[<li class="fail">- it (<a href="#details-1">FAILED - 1</a>)</li> + expect(@out).to eq(%[<li class="fail">- it (<a href="#details-1">FAILED - 1</a>)</li> <li class="fail">- it (<a href="#details-2">ERROR - 2</a>)</li> -] +]) end end -describe HtmlFormatter, "#after" do +RSpec.describe HtmlFormatter, "#after" do before :each do $stdout = @out = IOStub.new @formatter = HtmlFormatter.new @@ -129,7 +128,7 @@ describe HtmlFormatter, "#after" do it "prints the #it once when there are no exceptions raised" do @formatter.after @state - @out.should == %[<li class="pass">- it</li>\n] + expect(@out).to eq(%[<li class="pass">- it</li>\n]) end it "does not print any output if an exception is raised" do @@ -137,68 +136,73 @@ describe HtmlFormatter, "#after" do @formatter.exception exc out = @out.dup @formatter.after @state - @out.should == out + expect(@out).to eq(out) end end -describe HtmlFormatter, "#finish" do +RSpec.describe HtmlFormatter, "#finish" do before :each do @tally = double("tally").as_null_object - TallyAction.stub(:new).and_return(@tally) + allow(TallyAction).to receive(:new).and_return(@tally) @timer = double("timer").as_null_object - TimerAction.stub(:new).and_return(@timer) + allow(TimerAction).to receive(:new).and_return(@timer) + + @out = tmp("HtmlFormatter") - $stdout = @out = IOStub.new context = ContextState.new "describe" @state = ExampleState.new(context, "it") - MSpec.stub(:register) - @formatter = HtmlFormatter.new + allow(MSpec).to receive(:register) + @formatter = HtmlFormatter.new(@out) @formatter.register @exception = MSpecExampleError.new("broken") - @exception.stub(:backtrace).and_return(["file.rb:1", "file.rb:2"]) + allow(@exception).to receive(:backtrace).and_return(["file.rb:1", "file.rb:2"]) end after :each do - $stdout = STDOUT + rm_r @out end it "prints a failure message for an exception" do exc = ExceptionState.new @state, nil, @exception @formatter.exception exc @formatter.finish - @out.should include "<p>describe it ERROR</p>" + output = File.read(@out) + expect(output).to include "<p>describe it ERROR</p>" end it "prints a backtrace for an exception" do exc = ExceptionState.new @state, nil, @exception - exc.stub(:backtrace).and_return("path/to/some/file.rb:35:in method") + allow(exc).to receive(:backtrace).and_return("path/to/some/file.rb:35:in method") @formatter.exception exc @formatter.finish - @out.should =~ %r[<pre>.*path/to/some/file.rb:35:in method.*</pre>]m + output = File.read(@out) + expect(output).to match(%r[<pre>.*path/to/some/file.rb:35:in method.*</pre>]m) end it "prints a summary of elapsed time" do - @timer.should_receive(:format).and_return("Finished in 2.0 seconds") + expect(@timer).to receive(:format).and_return("Finished in 2.0 seconds") @formatter.finish - @out.should include "<p>Finished in 2.0 seconds</p>\n" + output = File.read(@out) + expect(output).to include "<p>Finished in 2.0 seconds</p>\n" end it "prints a tally of counts" do - @tally.should_receive(:format).and_return("1 example, 0 failures") + expect(@tally).to receive(:format).and_return("1 example, 0 failures") @formatter.finish - @out.should include '<p class="pass">1 example, 0 failures</p>' + output = File.read(@out) + expect(output).to include '<p class="pass">1 example, 0 failures</p>' end it "prints errors, backtraces, elapsed time, and tallies" do exc = ExceptionState.new @state, nil, @exception - exc.stub(:backtrace).and_return("path/to/some/file.rb:35:in method") + allow(exc).to receive(:backtrace).and_return("path/to/some/file.rb:35:in method") @formatter.exception exc - @timer.should_receive(:format).and_return("Finished in 2.0 seconds") - @tally.should_receive(:format).and_return("1 example, 1 failures") + expect(@timer).to receive(:format).and_return("Finished in 2.0 seconds") + expect(@tally).to receive(:format).and_return("1 example, 1 failures") @formatter.finish - @out.should == -%[<li class=\"fail\">- it (<a href=\"#details-1\">ERROR - 1</a>)</li> + output = File.read(@out) + expect(output).to eq(%[<li class=\"fail\">- it (<a href=\"#details-1\">ERROR - 1</a>)</li> <hr> <ol id="details"> <li id="details-1"><p>describe it ERROR</p> @@ -211,6 +215,6 @@ path/to/some/file.rb:35:in method</pre> <p class="fail">1 example, 1 failures</p> </body> </html> -] +]) end end diff --git a/spec/mspec/spec/runner/formatters/junit_spec.rb b/spec/mspec/spec/runner/formatters/junit_spec.rb index 66e7d70e92..3b3da73849 100644 --- a/spec/mspec/spec/runner/formatters/junit_spec.rb +++ b/spec/mspec/spec/runner/formatters/junit_spec.rb @@ -2,22 +2,23 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'mspec/runner/formatters/junit' require 'mspec/runner/example' +require 'mspec/helpers' -describe JUnitFormatter, "#initialize" do +RSpec.describe JUnitFormatter, "#initialize" do it "permits zero arguments" do - lambda { JUnitFormatter.new }.should_not raise_error + expect { JUnitFormatter.new }.not_to raise_error end it "accepts one argument" do - lambda { JUnitFormatter.new nil }.should_not raise_error + expect { JUnitFormatter.new nil }.not_to raise_error end end -describe JUnitFormatter, "#print" do +RSpec.describe JUnitFormatter, "#print" do before :each do $stdout = IOStub.new @out = IOStub.new - File.stub(:open).and_return(@out) + allow(File).to receive(:open).and_return(@out) @formatter = JUnitFormatter.new "some/file" end @@ -27,121 +28,132 @@ describe JUnitFormatter, "#print" do it "writes to $stdout if #switch has not been called" do @formatter.print "begonias" - $stdout.should == "begonias" - @out.should == "" + expect($stdout).to eq("begonias") + expect(@out).to eq("") end it "writes to the file passed to #initialize once #switch has been called" do @formatter.switch @formatter.print "begonias" - $stdout.should == "" - @out.should == "begonias" + expect($stdout).to eq("") + expect(@out).to eq("begonias") end it "writes to $stdout once #switch is called if no file was passed to #initialize" do formatter = JUnitFormatter.new formatter.switch formatter.print "begonias" - $stdout.should == "begonias" - @out.should == "" + expect($stdout).to eq("begonias") + expect(@out).to eq("") end end -describe JUnitFormatter, "#finish" do +RSpec.describe JUnitFormatter, "#finish" do before :each do @tally = double("tally").as_null_object @counter = double("counter").as_null_object - @tally.stub(:counter).and_return(@counter) - TallyAction.stub(:new).and_return(@tally) + allow(@tally).to receive(:counter).and_return(@counter) + allow(TallyAction).to receive(:new).and_return(@tally) @timer = double("timer").as_null_object - TimerAction.stub(:new).and_return(@timer) + allow(TimerAction).to receive(:new).and_return(@timer) + + @out = tmp("JUnitFormatter") - $stdout = IOStub.new context = ContextState.new "describe" @state = ExampleState.new(context, "it") - @formatter = JUnitFormatter.new - @formatter.stub(:backtrace).and_return("") - MSpec.stub(:register) + @formatter = JUnitFormatter.new(@out) + allow(@formatter).to receive(:backtrace).and_return("") + allow(MSpec).to receive(:register) @formatter.register exc = ExceptionState.new @state, nil, MSpecExampleError.new("broken") - exc.stub(:backtrace).and_return("path/to/some/file.rb:35:in method") + allow(exc).to receive(:backtrace).and_return("path/to/some/file.rb:35:in method") @formatter.exception exc @formatter.after @state end after :each do - $stdout = STDOUT + rm_r @out end it "calls #switch" do - @formatter.should_receive(:switch) + expect(@formatter).to receive(:switch).and_call_original @formatter.finish end it "outputs a failure message and backtrace" do @formatter.finish - $stdout.should include 'message="error in describe it" type="error"' - $stdout.should include "MSpecExampleError: broken\n" - $stdout.should include "path/to/some/file.rb:35:in method" + output = File.read(@out) + expect(output).to include 'message="error in describe it" type="error"' + expect(output).to include "MSpecExampleError: broken\n" + expect(output).to include "path/to/some/file.rb:35:in method" end it "encodes message and backtrace in latin1 for jenkins" do exc = ExceptionState.new @state, nil, MSpecExampleError.new("broken…") - exc.stub(:backtrace).and_return("path/to/some/file.rb:35:in methød") + allow(exc).to receive(:backtrace).and_return("path/to/some/file.rb:35:in methød") @formatter.exception exc @formatter.finish - $stdout.should =~ /MSpecExampleError: broken((\.\.\.)|\?)\n/ - $stdout.should =~ /path\/to\/some\/file\.rb:35:in meth(\?|o)d/ + output = File.binread(@out) + expect(output).to match(/MSpecExampleError: broken((\.\.\.)|\?)\n/) + expect(output).to match(/path\/to\/some\/file\.rb:35:in meth(\?|o)d/) end it "outputs an elapsed time" do - @timer.should_receive(:elapsed).and_return(4.2) + expect(@timer).to receive(:elapsed).and_return(4.2) @formatter.finish - $stdout.should include 'time="4.2"' + output = File.read(@out) + expect(output).to include 'time="4.2"' end it "outputs overall elapsed time" do - @timer.should_receive(:elapsed).and_return(4.2) + expect(@timer).to receive(:elapsed).and_return(4.2) @formatter.finish - $stdout.should include 'timeCount="4.2"' + output = File.read(@out) + expect(output).to include 'timeCount="4.2"' end it "outputs the number of examples as test count" do - @counter.should_receive(:examples).and_return(9) + expect(@counter).to receive(:examples).and_return(9) @formatter.finish - $stdout.should include 'tests="9"' + output = File.read(@out) + expect(output).to include 'tests="9"' end it "outputs overall number of examples as test count" do - @counter.should_receive(:examples).and_return(9) + expect(@counter).to receive(:examples).and_return(9) @formatter.finish - $stdout.should include 'testCount="9"' + output = File.read(@out) + expect(output).to include 'testCount="9"' end it "outputs a failure count" do - @counter.should_receive(:failures).and_return(2) + expect(@counter).to receive(:failures).and_return(2) @formatter.finish - $stdout.should include 'failureCount="2"' + output = File.read(@out) + expect(output).to include 'failureCount="2"' end it "outputs overall failure count" do - @counter.should_receive(:failures).and_return(2) + expect(@counter).to receive(:failures).and_return(2) @formatter.finish - $stdout.should include 'failures="2"' + output = File.read(@out) + expect(output).to include 'failures="2"' end it "outputs an error count" do - @counter.should_receive(:errors).and_return(1) + expect(@counter).to receive(:errors).and_return(1) @formatter.finish - $stdout.should include 'errors="1"' + output = File.read(@out) + expect(output).to include 'errors="1"' end it "outputs overall error count" do - @counter.should_receive(:errors).and_return(1) + expect(@counter).to receive(:errors).and_return(1) @formatter.finish - $stdout.should include 'errorCount="1"' + output = File.read(@out) + expect(output).to include 'errorCount="1"' end end diff --git a/spec/mspec/spec/runner/formatters/method_spec.rb b/spec/mspec/spec/runner/formatters/method_spec.rb index 77204f74c5..02bf47d538 100644 --- a/spec/mspec/spec/runner/formatters/method_spec.rb +++ b/spec/mspec/spec/runner/formatters/method_spec.rb @@ -4,29 +4,29 @@ require 'mspec/runner/mspec' require 'mspec/runner/example' require 'mspec/utils/script' -describe MethodFormatter, "#method_type" do +RSpec.describe MethodFormatter, "#method_type" do before :each do @formatter = MethodFormatter.new end it "returns 'class' if the separator is '.' or '::'" do - @formatter.method_type('.').should == "class" - @formatter.method_type('::').should == "class" + expect(@formatter.method_type('.')).to eq("class") + expect(@formatter.method_type('::')).to eq("class") end it "returns 'instance' if the separator is '#'" do - @formatter.method_type('#').should == "instance" + expect(@formatter.method_type('#')).to eq("instance") end it "returns 'unknown' for all other cases" do - @formatter.method_type(nil).should == "unknown" + expect(@formatter.method_type(nil)).to eq("unknown") end end -describe MethodFormatter, "#before" do +RSpec.describe MethodFormatter, "#before" do before :each do @formatter = MethodFormatter.new - MSpec.stub(:register) + allow(MSpec).to receive(:register) @formatter.register end @@ -38,32 +38,32 @@ describe MethodFormatter, "#before" do state = ExampleState.new ContextState.new("describe"), "it" @formatter.before state - @formatter.tally.counter.examples.should == 0 - @formatter.tally.counter.expectations.should == 0 - @formatter.tally.counter.failures.should == 0 - @formatter.tally.counter.errors.should == 0 + expect(@formatter.tally.counter.examples).to eq(0) + expect(@formatter.tally.counter.expectations).to eq(0) + expect(@formatter.tally.counter.failures).to eq(0) + expect(@formatter.tally.counter.errors).to eq(0) end it "records the class, method if available" do state = ExampleState.new ContextState.new("Some#method"), "it" @formatter.before state key = "Some#method" - @formatter.methods.keys.should include(key) + expect(@formatter.methods.keys).to include(key) h = @formatter.methods[key] - h[:class].should == "Some" - h[:method].should == "method" - h[:description].should == "Some#method it" + expect(h[:class]).to eq("Some") + expect(h[:method]).to eq("method") + expect(h[:description]).to eq("Some#method it") end it "does not record class, method unless both are available" do state = ExampleState.new ContextState.new("Some method"), "it" @formatter.before state key = "Some method" - @formatter.methods.keys.should include(key) + expect(@formatter.methods.keys).to include(key) h = @formatter.methods[key] - h[:class].should == "" - h[:method].should == "" - h[:description].should == "Some method it" + expect(h[:class]).to eq("") + expect(h[:method]).to eq("") + expect(h[:description]).to eq("Some method it") end it "sets the method type to unknown if class and method are not available" do @@ -71,7 +71,7 @@ describe MethodFormatter, "#before" do @formatter.before state key = "Some method" h = @formatter.methods[key] - h[:type].should == "unknown" + expect(h[:type]).to eq("unknown") end it "sets the method type based on the class, method separator" do @@ -79,7 +79,7 @@ describe MethodFormatter, "#before" do state = ExampleState.new ContextState.new(k), "it" @formatter.before state h = @formatter.methods[k] - h[:type].should == t + expect(h[:type]).to eq(t) end end @@ -87,14 +87,14 @@ describe MethodFormatter, "#before" do state = ExampleState.new ContextState.new("describe"), "it" @formatter.exceptions << "stuff" @formatter.before state - @formatter.exceptions.should be_empty + expect(@formatter.exceptions).to be_empty end end -describe MethodFormatter, "#after" do +RSpec.describe MethodFormatter, "#after" do before :each do @formatter = MethodFormatter.new - MSpec.stub(:register) + allow(MSpec).to receive(:register) @formatter.register end @@ -109,10 +109,10 @@ describe MethodFormatter, "#after" do @formatter.after state h = @formatter.methods["Some#method"] - h[:examples].should == 3 - h[:expectations].should == 4 - h[:failures].should == 2 - h[:errors].should == 1 + expect(h[:examples]).to eq(3) + expect(h[:expectations]).to eq(4) + expect(h[:failures]).to eq(2) + expect(h[:errors]).to eq(1) end it "renders the list of exceptions" do @@ -125,20 +125,20 @@ describe MethodFormatter, "#after" do @formatter.after state h = @formatter.methods["Some#method"] - h[:exceptions].should == [ + expect(h[:exceptions]).to eq([ %[failed\n\n], %[failed\n\n] - ] + ]) end end -describe MethodFormatter, "#after" do +RSpec.describe MethodFormatter, "#after" do before :each do $stdout = IOStub.new context = ContextState.new "Class#method" @state = ExampleState.new(context, "runs") @formatter = MethodFormatter.new - MSpec.stub(:register) + allow(MSpec).to receive(:register) @formatter.register end @@ -159,8 +159,7 @@ describe MethodFormatter, "#after" do @formatter.after @state @formatter.finish - $stdout.should == -%[--- + expect($stdout).to eq(%[--- "Class#method": class: "Class" method: "method" @@ -173,6 +172,6 @@ describe MethodFormatter, "#after" do exceptions: - "failed\\n\\n" - "failed\\n\\n" -] +]) end end diff --git a/spec/mspec/spec/runner/formatters/multi_spec.rb b/spec/mspec/spec/runner/formatters/multi_spec.rb index d0ed8edc93..2d13c05836 100644 --- a/spec/mspec/spec/runner/formatters/multi_spec.rb +++ b/spec/mspec/spec/runner/formatters/multi_spec.rb @@ -4,20 +4,20 @@ require 'mspec/runner/formatters/multi' require 'mspec/runner/example' require 'yaml' -describe MultiFormatter, "#aggregate_results" do +RSpec.describe MultiFormatter, "#aggregate_results" do before :each do @stdout, $stdout = $stdout, IOStub.new @file = double("file").as_null_object - File.stub(:delete) - File.stub(:read) + allow(File).to receive(:delete) + allow(File).to receive(:read) @hash = { "files"=>1, "examples"=>1, "expectations"=>2, "failures"=>0, "errors"=>0 } - YAML.stub(:load).and_return(@hash) + allow(YAML).to receive(:load).and_return(@hash) @formatter = DottedFormatter.new.extend(MultiFormatter) - @formatter.timer.stub(:format).and_return("Finished in 42 seconds") + allow(@formatter.timer).to receive(:format).and_return("Finished in 42 seconds") end after :each do @@ -27,13 +27,12 @@ describe MultiFormatter, "#aggregate_results" do it "outputs a summary without errors" do @formatter.aggregate_results(["a", "b"]) @formatter.finish - $stdout.should == -%[ + expect($stdout).to eq(%[ Finished in 42 seconds 2 files, 2 examples, 4 expectations, 0 failures, 0 errors, 0 tagged -] +]) end it "outputs a summary with errors" do @@ -43,8 +42,7 @@ Finished in 42 seconds ] @formatter.aggregate_results(["a"]) @formatter.finish - $stdout.should == -%[ + expect($stdout).to eq(%[ 1) Some#method works real good FAILED @@ -65,6 +63,6 @@ foo.rb:2 Finished in 42 seconds 1 file, 1 example, 2 expectations, 0 failures, 0 errors, 0 tagged -] +]) end end diff --git a/spec/mspec/spec/runner/formatters/specdoc_spec.rb b/spec/mspec/spec/runner/formatters/specdoc_spec.rb index edb439fc11..54b5e2cf0d 100644 --- a/spec/mspec/spec/runner/formatters/specdoc_spec.rb +++ b/spec/mspec/spec/runner/formatters/specdoc_spec.rb @@ -2,19 +2,19 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'mspec/runner/formatters/specdoc' require 'mspec/runner/example' -describe SpecdocFormatter do +RSpec.describe SpecdocFormatter do before :each do @formatter = SpecdocFormatter.new end it "responds to #register by registering itself with MSpec for appropriate actions" do - MSpec.stub(:register) - MSpec.should_receive(:register).with(:enter, @formatter) + allow(MSpec).to receive(:register) + expect(MSpec).to receive(:register).with(:enter, @formatter) @formatter.register end end -describe SpecdocFormatter, "#enter" do +RSpec.describe SpecdocFormatter, "#enter" do before :each do $stdout = @out = IOStub.new @formatter = SpecdocFormatter.new @@ -26,11 +26,11 @@ describe SpecdocFormatter, "#enter" do it "prints the #describe string" do @formatter.enter("describe") - @out.should == "\ndescribe\n" + expect(@out).to eq("\ndescribe\n") end end -describe SpecdocFormatter, "#before" do +RSpec.describe SpecdocFormatter, "#before" do before :each do $stdout = @out = IOStub.new @formatter = SpecdocFormatter.new @@ -43,19 +43,19 @@ describe SpecdocFormatter, "#before" do it "prints the #it string" do @formatter.before @state - @out.should == "- it" + expect(@out).to eq("- it") end it "resets the #exception? flag" do exc = ExceptionState.new @state, nil, SpecExpectationNotMetError.new("disappointing") @formatter.exception exc - @formatter.exception?.should be_true + expect(@formatter.exception?).to be_truthy @formatter.before @state - @formatter.exception?.should be_false + expect(@formatter.exception?).to be_falsey end end -describe SpecdocFormatter, "#exception" do +RSpec.describe SpecdocFormatter, "#exception" do before :each do $stdout = @out = IOStub.new @formatter = SpecdocFormatter.new @@ -70,13 +70,13 @@ describe SpecdocFormatter, "#exception" do it "prints 'ERROR' if an exception is not an SpecExpectationNotMetError" do exc = ExceptionState.new @state, nil, MSpecExampleError.new("painful") @formatter.exception exc - @out.should == " (ERROR - 1)" + expect(@out).to eq(" (ERROR - 1)") end it "prints 'FAILED' if an exception is an SpecExpectationNotMetError" do exc = ExceptionState.new @state, nil, SpecExpectationNotMetError.new("disappointing") @formatter.exception exc - @out.should == " (FAILED - 1)" + expect(@out).to eq(" (FAILED - 1)") end it "prints the #it string if an exception has already been raised" do @@ -84,11 +84,11 @@ describe SpecdocFormatter, "#exception" do @formatter.exception exc exc = ExceptionState.new @state, nil, MSpecExampleError.new("painful") @formatter.exception exc - @out.should == " (FAILED - 1)\n- it (ERROR - 2)" + expect(@out).to eq(" (FAILED - 1)\n- it (ERROR - 2)") end end -describe SpecdocFormatter, "#after" do +RSpec.describe SpecdocFormatter, "#after" do before :each do $stdout = @out = IOStub.new @formatter = SpecdocFormatter.new @@ -101,6 +101,6 @@ describe SpecdocFormatter, "#after" do it "prints a newline character" do @formatter.after @state - @out.should == "\n" + expect(@out).to eq("\n") end end diff --git a/spec/mspec/spec/runner/formatters/spinner_spec.rb b/spec/mspec/spec/runner/formatters/spinner_spec.rb index a122620e39..5c93d38822 100644 --- a/spec/mspec/spec/runner/formatters/spinner_spec.rb +++ b/spec/mspec/spec/runner/formatters/spinner_spec.rb @@ -3,7 +3,7 @@ require 'mspec/runner/formatters/spinner' require 'mspec/runner/mspec' require 'mspec/runner/example' -describe SpinnerFormatter, "#initialize" do +RSpec.describe SpinnerFormatter, "#initialize" do it "permits zero arguments" do SpinnerFormatter.new end @@ -13,33 +13,33 @@ describe SpinnerFormatter, "#initialize" do end end -describe SpinnerFormatter, "#register" do +RSpec.describe SpinnerFormatter, "#register" do before :each do @formatter = SpinnerFormatter.new - MSpec.stub(:register) + allow(MSpec).to receive(:register) end it "registers self with MSpec for appropriate actions" do - MSpec.should_receive(:register).with(:start, @formatter) - MSpec.should_receive(:register).with(:unload, @formatter) - MSpec.should_receive(:register).with(:after, @formatter) - MSpec.should_receive(:register).with(:finish, @formatter) + expect(MSpec).to receive(:register).with(:start, @formatter) + expect(MSpec).to receive(:register).with(:unload, @formatter) + expect(MSpec).to receive(:register).with(:after, @formatter) + expect(MSpec).to receive(:register).with(:finish, @formatter) @formatter.register end it "creates TimerAction and TallyAction" do timer = double("timer") tally = double("tally") - timer.should_receive(:register) - tally.should_receive(:register) - tally.should_receive(:counter) - TimerAction.should_receive(:new).and_return(timer) - TallyAction.should_receive(:new).and_return(tally) + expect(timer).to receive(:register) + expect(tally).to receive(:register) + expect(tally).to receive(:counter) + expect(TimerAction).to receive(:new).and_return(timer) + expect(TallyAction).to receive(:new).and_return(tally) @formatter.register end end -describe SpinnerFormatter, "#print" do +RSpec.describe SpinnerFormatter, "#print" do after :each do $stdout = STDOUT end @@ -48,11 +48,11 @@ describe SpinnerFormatter, "#print" do $stdout = IOStub.new formatter = SpinnerFormatter.new "some/file" formatter.print "begonias" - $stdout.should == "begonias" + expect($stdout).to eq("begonias") end end -describe SpinnerFormatter, "#after" do +RSpec.describe SpinnerFormatter, "#after" do before :each do $stdout = IOStub.new MSpec.store(:files, ["a", "b", "c", "d"]) @@ -78,6 +78,6 @@ describe SpinnerFormatter, "#after" do output = "\r[/ | 0% | 00:00:00] #{green} 0F #{green} 0E#{reset} " \ "\r[- | 0% | 00:00:00] #{green} 0F #{green} 0E#{reset} " \ "\r[\\ | ========== 25% | 00:00:00] #{green} 0F #{green} 0E#{reset} " - $stdout.should == output + expect($stdout).to eq(output) end end diff --git a/spec/mspec/spec/runner/formatters/summary_spec.rb b/spec/mspec/spec/runner/formatters/summary_spec.rb index 16a156b695..c87d940042 100644 --- a/spec/mspec/spec/runner/formatters/summary_spec.rb +++ b/spec/mspec/spec/runner/formatters/summary_spec.rb @@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'mspec/runner/formatters/summary' require 'mspec/runner/example' -describe SummaryFormatter, "#after" do +RSpec.describe SummaryFormatter, "#after" do before :each do $stdout = @out = IOStub.new @formatter = SummaryFormatter.new @@ -21,6 +21,6 @@ describe SummaryFormatter, "#after" do exc = ExceptionState.new @state, nil, MSpecExampleError.new("painful") @formatter.exception exc @formatter.after(@state) - @out.should == "" + expect(@out).to eq("") end end diff --git a/spec/mspec/spec/runner/formatters/unit_spec.rb b/spec/mspec/spec/runner/formatters/unit_spec.rb index 18167a32b8..d349e6871d 100644 --- a/spec/mspec/spec/runner/formatters/unit_spec.rb +++ b/spec/mspec/spec/runner/formatters/unit_spec.rb @@ -3,17 +3,17 @@ require 'mspec/runner/formatters/unit' require 'mspec/runner/example' require 'mspec/utils/script' -describe UnitdiffFormatter, "#finish" do +RSpec.describe UnitdiffFormatter, "#finish" do before :each do @tally = double("tally").as_null_object - TallyAction.stub(:new).and_return(@tally) + allow(TallyAction).to receive(:new).and_return(@tally) @timer = double("timer").as_null_object - TimerAction.stub(:new).and_return(@timer) + allow(TimerAction).to receive(:new).and_return(@timer) $stdout = @out = IOStub.new context = ContextState.new "describe" @state = ExampleState.new(context, "it") - MSpec.stub(:register) + allow(MSpec).to receive(:register) @formatter = UnitdiffFormatter.new @formatter.register end @@ -27,39 +27,38 @@ describe UnitdiffFormatter, "#finish" do @formatter.exception exc @formatter.after @state @formatter.finish - @out.should =~ /^1\)\ndescribe it ERROR$/ + expect(@out).to match(/^1\)\ndescribe it ERROR$/) end it "prints a backtrace for an exception" do exc = ExceptionState.new @state, nil, Exception.new("broken") - exc.stub(:backtrace).and_return("path/to/some/file.rb:35:in method") + allow(exc).to receive(:backtrace).and_return("path/to/some/file.rb:35:in method") @formatter.exception exc @formatter.finish - @out.should =~ %r[path/to/some/file.rb:35:in method$] + expect(@out).to match(%r[path/to/some/file.rb:35:in method$]) end it "prints a summary of elapsed time" do - @timer.should_receive(:format).and_return("Finished in 2.0 seconds") + expect(@timer).to receive(:format).and_return("Finished in 2.0 seconds") @formatter.finish - @out.should =~ /^Finished in 2.0 seconds$/ + expect(@out).to match(/^Finished in 2.0 seconds$/) end it "prints a tally of counts" do - @tally.should_receive(:format).and_return("1 example, 0 failures") + expect(@tally).to receive(:format).and_return("1 example, 0 failures") @formatter.finish - @out.should =~ /^1 example, 0 failures$/ + expect(@out).to match(/^1 example, 0 failures$/) end it "prints errors, backtraces, elapsed time, and tallies" do exc = ExceptionState.new @state, nil, Exception.new("broken") - exc.stub(:backtrace).and_return("path/to/some/file.rb:35:in method") + allow(exc).to receive(:backtrace).and_return("path/to/some/file.rb:35:in method") @formatter.exception exc @formatter.after @state - @timer.should_receive(:format).and_return("Finished in 2.0 seconds") - @tally.should_receive(:format).and_return("1 example, 0 failures") + expect(@timer).to receive(:format).and_return("Finished in 2.0 seconds") + expect(@tally).to receive(:format).and_return("1 example, 0 failures") @formatter.finish - @out.should == -%[E + expect(@out).to eq(%[E Finished in 2.0 seconds @@ -69,6 +68,6 @@ Exception: broken: path/to/some/file.rb:35:in method 1 example, 0 failures -] +]) end end diff --git a/spec/mspec/spec/runner/formatters/yaml_spec.rb b/spec/mspec/spec/runner/formatters/yaml_spec.rb index eb4d99f74c..2e334fdbb9 100644 --- a/spec/mspec/spec/runner/formatters/yaml_spec.rb +++ b/spec/mspec/spec/runner/formatters/yaml_spec.rb @@ -1,8 +1,9 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'mspec/runner/formatters/yaml' require 'mspec/runner/example' +require 'mspec/helpers' -describe YamlFormatter, "#initialize" do +RSpec.describe YamlFormatter, "#initialize" do it "permits zero arguments" do YamlFormatter.new end @@ -12,11 +13,11 @@ describe YamlFormatter, "#initialize" do end end -describe YamlFormatter, "#print" do +RSpec.describe YamlFormatter, "#print" do before :each do $stdout = IOStub.new @out = IOStub.new - File.stub(:open).and_return(@out) + allow(File).to receive(:open).and_return(@out) @formatter = YamlFormatter.new "some/file" end @@ -26,100 +27,108 @@ describe YamlFormatter, "#print" do it "writes to $stdout if #switch has not been called" do @formatter.print "begonias" - $stdout.should == "begonias" - @out.should == "" + expect($stdout).to eq("begonias") + expect(@out).to eq("") end it "writes to the file passed to #initialize once #switch has been called" do @formatter.switch @formatter.print "begonias" - $stdout.should == "" - @out.should == "begonias" + expect($stdout).to eq("") + expect(@out).to eq("begonias") end it "writes to $stdout once #switch is called if no file was passed to #initialize" do formatter = YamlFormatter.new formatter.switch formatter.print "begonias" - $stdout.should == "begonias" - @out.should == "" + expect($stdout).to eq("begonias") + expect(@out).to eq("") end end -describe YamlFormatter, "#finish" do +RSpec.describe YamlFormatter, "#finish" do before :each do @tally = double("tally").as_null_object @counter = double("counter").as_null_object - @tally.stub(:counter).and_return(@counter) - TallyAction.stub(:new).and_return(@tally) + allow(@tally).to receive(:counter).and_return(@counter) + allow(TallyAction).to receive(:new).and_return(@tally) @timer = double("timer").as_null_object - TimerAction.stub(:new).and_return(@timer) + allow(TimerAction).to receive(:new).and_return(@timer) + + @out = tmp("YamlFormatter") - $stdout = IOStub.new context = ContextState.new "describe" @state = ExampleState.new(context, "it") - @formatter = YamlFormatter.new - @formatter.stub(:backtrace).and_return("") - MSpec.stub(:register) + @formatter = YamlFormatter.new(@out) + allow(@formatter).to receive(:backtrace).and_return("") + allow(MSpec).to receive(:register) @formatter.register exc = ExceptionState.new @state, nil, MSpecExampleError.new("broken") - exc.stub(:backtrace).and_return("path/to/some/file.rb:35:in method") + allow(exc).to receive(:backtrace).and_return("path/to/some/file.rb:35:in method") @formatter.exception exc @formatter.after @state end after :each do - $stdout = STDOUT + rm_r @out end it "calls #switch" do - @formatter.should_receive(:switch) + expect(@formatter).to receive(:switch).and_call_original @formatter.finish end it "outputs a failure message and backtrace" do @formatter.finish - $stdout.should include "describe it ERROR" - $stdout.should include "MSpecExampleError: broken\\n" - $stdout.should include "path/to/some/file.rb:35:in method" + output = File.read(@out) + expect(output).to include "describe it ERROR" + expect(output).to include "MSpecExampleError: broken\\n" + expect(output).to include "path/to/some/file.rb:35:in method" end it "outputs an elapsed time" do - @timer.should_receive(:elapsed).and_return(4.2) + expect(@timer).to receive(:elapsed).and_return(4.2) @formatter.finish - $stdout.should include "time: 4.2" + output = File.read(@out) + expect(output).to include "time: 4.2" end it "outputs a file count" do - @counter.should_receive(:files).and_return(3) + expect(@counter).to receive(:files).and_return(3) @formatter.finish - $stdout.should include "files: 3" + output = File.read(@out) + expect(output).to include "files: 3" end it "outputs an example count" do - @counter.should_receive(:examples).and_return(3) + expect(@counter).to receive(:examples).and_return(3) @formatter.finish - $stdout.should include "examples: 3" + output = File.read(@out) + expect(output).to include "examples: 3" end it "outputs an expectation count" do - @counter.should_receive(:expectations).and_return(9) + expect(@counter).to receive(:expectations).and_return(9) @formatter.finish - $stdout.should include "expectations: 9" + output = File.read(@out) + expect(output).to include "expectations: 9" end it "outputs a failure count" do - @counter.should_receive(:failures).and_return(2) + expect(@counter).to receive(:failures).and_return(2) @formatter.finish - $stdout.should include "failures: 2" + output = File.read(@out) + expect(output).to include "failures: 2" end it "outputs an error count" do - @counter.should_receive(:errors).and_return(1) + expect(@counter).to receive(:errors).and_return(1) @formatter.finish - $stdout.should include "errors: 1" + output = File.read(@out) + expect(output).to include "errors: 1" end end diff --git a/spec/mspec/spec/runner/mspec_spec.rb b/spec/mspec/spec/runner/mspec_spec.rb index 7dad4458d3..4af01806c0 100644 --- a/spec/mspec/spec/runner/mspec_spec.rb +++ b/spec/mspec/spec/runner/mspec_spec.rb @@ -6,93 +6,93 @@ require 'mspec/matchers/base' require 'mspec/runner/mspec' require 'mspec/runner/example' -describe MSpec, ".register_files" do +RSpec.describe MSpec, ".register_files" do it "records which spec files to run" do MSpec.register_files [:one, :two, :three] - MSpec.files_array.should == [:one, :two, :three] + expect(MSpec.files_array).to eq([:one, :two, :three]) end end -describe MSpec, ".register_mode" do +RSpec.describe MSpec, ".register_mode" do before :each do MSpec.clear_modes end it "sets execution mode flags" do MSpec.register_mode :verify - MSpec.retrieve(:modes).should == [:verify] + expect(MSpec.retrieve(:modes)).to eq([:verify]) end end -describe MSpec, ".register_tags_patterns" do +RSpec.describe MSpec, ".register_tags_patterns" do it "records the patterns for generating a tag file from a spec file" do MSpec.register_tags_patterns [[/spec\/ruby/, "spec/tags"], [/frozen/, "ruby"]] - MSpec.retrieve(:tags_patterns).should == [[/spec\/ruby/, "spec/tags"], [/frozen/, "ruby"]] + expect(MSpec.retrieve(:tags_patterns)).to eq([[/spec\/ruby/, "spec/tags"], [/frozen/, "ruby"]]) end end -describe MSpec, ".register_exit" do +RSpec.describe MSpec, ".register_exit" do before :each do MSpec.store :exit, 0 end it "records the exit code" do - MSpec.exit_code.should == 0 + expect(MSpec.exit_code).to eq(0) MSpec.register_exit 1 - MSpec.exit_code.should == 1 + expect(MSpec.exit_code).to eq(1) end end -describe MSpec, ".exit_code" do +RSpec.describe MSpec, ".exit_code" do it "retrieves the code set with .register_exit" do MSpec.register_exit 99 - MSpec.exit_code.should == 99 + expect(MSpec.exit_code).to eq(99) end end -describe MSpec, ".store" do +RSpec.describe MSpec, ".store" do it "records data for MSpec settings" do MSpec.store :anything, :value - MSpec.retrieve(:anything).should == :value + expect(MSpec.retrieve(:anything)).to eq(:value) end end -describe MSpec, ".retrieve" do +RSpec.describe MSpec, ".retrieve" do it "accesses .store'd data" do MSpec.register :retrieve, :first - MSpec.retrieve(:retrieve).should == [:first] + expect(MSpec.retrieve(:retrieve)).to eq([:first]) end end -describe MSpec, ".randomize" do +RSpec.describe MSpec, ".randomize" do it "sets the flag to randomize spec execution order" do - MSpec.randomize?.should == false + expect(MSpec.randomize?).to eq(false) MSpec.randomize = true - MSpec.randomize?.should == true + expect(MSpec.randomize?).to eq(true) MSpec.randomize = false - MSpec.randomize?.should == false + expect(MSpec.randomize?).to eq(false) end end -describe MSpec, ".register" do +RSpec.describe MSpec, ".register" do it "is the gateway behind the register(symbol, action) facility" do MSpec.register :bonus, :first MSpec.register :bonus, :second MSpec.register :bonus, :second - MSpec.retrieve(:bonus).should == [:first, :second] + expect(MSpec.retrieve(:bonus)).to eq([:first, :second]) end end -describe MSpec, ".unregister" do +RSpec.describe MSpec, ".unregister" do it "is the gateway behind the unregister(symbol, actions) facility" do MSpec.register :unregister, :first MSpec.register :unregister, :second MSpec.unregister :unregister, :second - MSpec.retrieve(:unregister).should == [:first] + expect(MSpec.retrieve(:unregister)).to eq([:first]) end end -describe MSpec, ".protect" do +RSpec.describe MSpec, ".protect" do before :each do MSpec.clear_current @cs = ContextState.new "C#m" @@ -103,11 +103,11 @@ describe MSpec, ".protect" do end it "returns true if no exception is raised" do - MSpec.protect("passed") { 1 }.should be_true + expect(MSpec.protect("passed") { 1 }).to be_truthy end it "returns false if an exception is raised" do - MSpec.protect("testing") { raise ScratchPad.recorded }.should be_false + expect(MSpec.protect("testing") { raise ScratchPad.recorded }).to be_falsey end it "rescues any exceptions raised when evaluating the block argument" do @@ -120,231 +120,230 @@ describe MSpec, ".protect" do rescue SystemExit ScratchPad.record :system_exit end - ScratchPad.recorded.should == :system_exit + expect(ScratchPad.recorded).to eq(:system_exit) end it "calls all the exception actions" do exc = ExceptionState.new @es, "testing", ScratchPad.recorded - ExceptionState.stub(:new).and_return(exc) + allow(ExceptionState).to receive(:new).and_return(exc) action = double("exception") - action.should_receive(:exception).with(exc) + expect(action).to receive(:exception).with(exc) MSpec.register :exception, action MSpec.protect("testing") { raise ScratchPad.recorded } MSpec.unregister :exception, action end it "registers a non-zero exit code when an exception is raised" do - MSpec.should_receive(:register_exit).with(1) + expect(MSpec).to receive(:register_exit).with(1) MSpec.protect("testing") { raise ScratchPad.recorded } end end -describe MSpec, ".register_current" do +RSpec.describe MSpec, ".register_current" do before :each do MSpec.clear_current end it "sets the value returned by MSpec.current" do - MSpec.current.should be_nil + expect(MSpec.current).to be_nil MSpec.register_current :a - MSpec.current.should == :a + expect(MSpec.current).to eq(:a) end end -describe MSpec, ".clear_current" do +RSpec.describe MSpec, ".clear_current" do it "sets the value returned by MSpec.current to nil" do MSpec.register_current :a - MSpec.current.should_not be_nil + expect(MSpec.current).not_to be_nil MSpec.clear_current - MSpec.current.should be_nil + expect(MSpec.current).to be_nil end end -describe MSpec, ".current" do +RSpec.describe MSpec, ".current" do before :each do MSpec.clear_current end it "returns nil if no ContextState has been registered" do - MSpec.current.should be_nil + expect(MSpec.current).to be_nil end it "returns the most recently registered ContextState" do first = ContextState.new "" second = ContextState.new "" MSpec.register_current first - MSpec.current.should == first + expect(MSpec.current).to eq(first) MSpec.register_current second - MSpec.current.should == second + expect(MSpec.current).to eq(second) end end -describe MSpec, ".actions" do +RSpec.describe MSpec, ".actions" do before :each do MSpec.store :start, [] ScratchPad.record [] start_one = double("one") - start_one.stub(:start).and_return { ScratchPad << :one } + allow(start_one).to receive(:start) { ScratchPad << :one } start_two = double("two") - start_two.stub(:start).and_return { ScratchPad << :two } + allow(start_two).to receive(:start) { ScratchPad << :two } MSpec.register :start, start_one MSpec.register :start, start_two end it "does not attempt to run any actions if none have been registered" do MSpec.store :finish, nil - lambda { MSpec.actions :finish }.should_not raise_error + expect { MSpec.actions :finish }.not_to raise_error end it "runs each action registered as a start action" do MSpec.actions :start - ScratchPad.recorded.should == [:one, :two] + expect(ScratchPad.recorded).to eq([:one, :two]) end end -describe MSpec, ".mode?" do +RSpec.describe MSpec, ".mode?" do before :each do MSpec.clear_modes end it "returns true if the mode has been set" do - MSpec.mode?(:verify).should == false + expect(MSpec.mode?(:verify)).to eq(false) MSpec.register_mode :verify - MSpec.mode?(:verify).should == true + expect(MSpec.mode?(:verify)).to eq(true) end end -describe MSpec, ".clear_modes" do +RSpec.describe MSpec, ".clear_modes" do it "clears all registered modes" do MSpec.register_mode(:pretend) MSpec.register_mode(:verify) - MSpec.mode?(:pretend).should == true - MSpec.mode?(:verify).should == true + expect(MSpec.mode?(:pretend)).to eq(true) + expect(MSpec.mode?(:verify)).to eq(true) MSpec.clear_modes - MSpec.mode?(:pretend).should == false - MSpec.mode?(:verify).should == false + expect(MSpec.mode?(:pretend)).to eq(false) + expect(MSpec.mode?(:verify)).to eq(false) end end -describe MSpec, ".guarded?" do +RSpec.describe MSpec, ".guarded?" do before :each do MSpec.instance_variable_set :@guarded, [] end it "returns false if no guard has run" do - MSpec.guarded?.should == false + expect(MSpec.guarded?).to eq(false) end it "returns true if a single guard has run" do MSpec.guard - MSpec.guarded?.should == true + expect(MSpec.guarded?).to eq(true) end it "returns true if more than one guard has run" do MSpec.guard MSpec.guard - MSpec.guarded?.should == true + expect(MSpec.guarded?).to eq(true) end it "returns true until all guards have finished" do MSpec.guard MSpec.guard - MSpec.guarded?.should == true + expect(MSpec.guarded?).to eq(true) MSpec.unguard - MSpec.guarded?.should == true + expect(MSpec.guarded?).to eq(true) MSpec.unguard - MSpec.guarded?.should == false + expect(MSpec.guarded?).to eq(false) end end -describe MSpec, ".describe" do +RSpec.describe MSpec, ".describe" do before :each do MSpec.clear_current @cs = ContextState.new "" - ContextState.stub(:new).and_return(@cs) - MSpec.stub(:current).and_return(nil) - MSpec.stub(:register_current) + allow(ContextState).to receive(:new).and_return(@cs) + allow(MSpec).to receive(:current).and_return(nil) + allow(MSpec).to receive(:register_current) end it "creates a new ContextState for the block" do - ContextState.should_receive(:new).and_return(@cs) + expect(ContextState).to receive(:new).and_return(@cs) MSpec.describe(Object) { } end it "accepts an optional second argument" do - ContextState.should_receive(:new).and_return(@cs) + expect(ContextState).to receive(:new).and_return(@cs) MSpec.describe(Object, "msg") { } end it "registers the newly created ContextState" do - MSpec.should_receive(:register_current).with(@cs).twice + expect(MSpec).to receive(:register_current).with(@cs).twice MSpec.describe(Object) { } end it "invokes the ContextState#describe method" do - prc = lambda { } - @cs.should_receive(:describe).with(&prc) - MSpec.describe(Object, "msg", &prc) + expect(@cs).to receive(:describe) + MSpec.describe(Object, "msg") {} end end -describe MSpec, ".process" do +RSpec.describe MSpec, ".process" do before :each do - MSpec.stub(:files) + allow(MSpec).to receive(:files) MSpec.store :start, [] MSpec.store :finish, [] - STDOUT.stub(:puts) + allow(STDOUT).to receive(:puts) end it "prints the RUBY_DESCRIPTION" do - STDOUT.should_receive(:puts).with(RUBY_DESCRIPTION) + expect(STDOUT).to receive(:puts).with(RUBY_DESCRIPTION) MSpec.process end it "calls all start actions" do start = double("start") - start.stub(:start).and_return { ScratchPad.record :start } + allow(start).to receive(:start) { ScratchPad.record :start } MSpec.register :start, start MSpec.process - ScratchPad.recorded.should == :start + expect(ScratchPad.recorded).to eq(:start) end it "calls all finish actions" do finish = double("finish") - finish.stub(:finish).and_return { ScratchPad.record :finish } + allow(finish).to receive(:finish) { ScratchPad.record :finish } MSpec.register :finish, finish MSpec.process - ScratchPad.recorded.should == :finish + expect(ScratchPad.recorded).to eq(:finish) end it "calls the files method" do - MSpec.should_receive(:files) + expect(MSpec).to receive(:files) MSpec.process end end -describe MSpec, ".files" do +RSpec.describe MSpec, ".files" do before :each do MSpec.store :load, [] MSpec.store :unload, [] MSpec.register_files [:one, :two, :three] - Kernel.stub(:load) + allow(Kernel).to receive(:load) end it "calls load actions before each file" do load = double("load") - load.stub(:load).and_return { ScratchPad.record :load } + allow(load).to receive(:load) { ScratchPad.record :load } MSpec.register :load, load MSpec.files - ScratchPad.recorded.should == :load + expect(ScratchPad.recorded).to eq(:load) end it "shuffles the file list if .randomize? is true" do MSpec.randomize = true - MSpec.should_receive(:shuffle) + expect(MSpec).to receive(:shuffle) MSpec.files MSpec.randomize = false end @@ -352,14 +351,14 @@ describe MSpec, ".files" do it "registers the current file" do load = double("load") files = [] - load.stub(:load).and_return { files << MSpec.file } + allow(load).to receive(:load) { files << MSpec.file } MSpec.register :load, load MSpec.files - files.should == [:one, :two, :three] + expect(files).to eq([:one, :two, :three]) end end -describe MSpec, ".shuffle" do +RSpec.describe MSpec, ".shuffle" do before :each do @base = (0..100).to_a @list = @base.clone @@ -368,30 +367,30 @@ describe MSpec, ".shuffle" do it "does not alter the elements in the list" do @base.each do |elt| - @list.should include(elt) + expect(@list).to include(elt) end end it "changes the order of the list" do # obviously, this spec has a certain probability # of failing. If it fails, run it again. - @list.should_not == @base + expect(@list).not_to eq(@base) end end -describe MSpec, ".tags_file" do +RSpec.describe MSpec, ".tags_file" do before :each do MSpec.store :file, "path/to/spec/something/some_spec.rb" MSpec.store :tags_patterns, nil end it "returns the default tags file for the current spec file" do - MSpec.tags_file.should == "path/to/spec/tags/something/some_tags.txt" + expect(MSpec.tags_file).to eq("path/to/spec/tags/something/some_tags.txt") end it "returns the tags file for the current spec file with custom tags_patterns" do MSpec.register_tags_patterns [[/^(.*)\/spec/, '\1/tags'], [/_spec.rb/, "_tags.txt"]] - MSpec.tags_file.should == "path/to/tags/something/some_tags.txt" + expect(MSpec.tags_file).to eq("path/to/tags/something/some_tags.txt") end it "performs multiple substitutions" do @@ -400,31 +399,31 @@ describe MSpec, ".tags_file" do [%r(/spec/), "/spec/tags/"], [/_spec.rb/, "_tags.txt"] ] - MSpec.tags_file.should == "path/to/spec/tags/other/some_tags.txt" + expect(MSpec.tags_file).to eq("path/to/spec/tags/other/some_tags.txt") end it "handles cases where no substitution is performed" do MSpec.register_tags_patterns [[/nothing/, "something"]] - MSpec.tags_file.should == "path/to/spec/something/some_spec.rb" + expect(MSpec.tags_file).to eq("path/to/spec/something/some_spec.rb") end end -describe MSpec, ".read_tags" do +RSpec.describe MSpec, ".read_tags" do before :each do - MSpec.stub(:tags_file).and_return(File.dirname(__FILE__) + '/tags.txt') + allow(MSpec).to receive(:tags_file).and_return(File.dirname(__FILE__) + '/tags.txt') end it "returns a list of tag instances for matching tag names found" do one = SpecTag.new "fail(broken):Some#method? works" - MSpec.read_tags(["fail", "pass"]).should == [one] + expect(MSpec.read_tags(["fail", "pass"])).to eq([one]) end it "returns [] if no tags names match" do - MSpec.read_tags("super").should == [] + expect(MSpec.read_tags("super")).to eq([]) end end -describe MSpec, ".read_tags" do +RSpec.describe MSpec, ".read_tags" do before :each do @tag = SpecTag.new "fails:Some#method" File.open(tmp("tags.txt", false), "w") do |f| @@ -432,18 +431,18 @@ describe MSpec, ".read_tags" do f.puts @tag f.puts "" end - MSpec.stub(:tags_file).and_return(tmp("tags.txt", false)) + allow(MSpec).to receive(:tags_file).and_return(tmp("tags.txt", false)) end it "does not return a tag object for empty lines" do - MSpec.read_tags(["fails"]).should == [@tag] + expect(MSpec.read_tags(["fails"])).to eq([@tag]) end end -describe MSpec, ".write_tags" do +RSpec.describe MSpec, ".write_tags" do before :each do FileUtils.cp File.dirname(__FILE__) + "/tags.txt", tmp("tags.txt", false) - MSpec.stub(:tags_file).and_return(tmp("tags.txt", false)) + allow(MSpec).to receive(:tags_file).and_return(tmp("tags.txt", false)) @tag1 = SpecTag.new "check(broken):Tag#rewrite works" @tag2 = SpecTag.new "broken:Tag#write_tags fails" end @@ -453,22 +452,22 @@ describe MSpec, ".write_tags" do end it "overwrites the tags in the tag file" do - IO.read(tmp("tags.txt", false)).should == %[fail(broken):Some#method? works + expect(IO.read(tmp("tags.txt", false))).to eq(%[fail(broken):Some#method? works incomplete(20%):The#best method ever benchmark(0.01825):The#fastest method today extended():\"Multi-line\\ntext\\ntag\" -] +]) MSpec.write_tags [@tag1, @tag2] - IO.read(tmp("tags.txt", false)).should == %[check(broken):Tag#rewrite works + expect(IO.read(tmp("tags.txt", false))).to eq(%[check(broken):Tag#rewrite works broken:Tag#write_tags fails -] +]) end end -describe MSpec, ".write_tag" do +RSpec.describe MSpec, ".write_tag" do before :each do - FileUtils.stub(:mkdir_p) - MSpec.stub(:tags_file).and_return(tmp("tags.txt", false)) + allow(FileUtils).to receive(:mkdir_p) + allow(MSpec).to receive(:tags_file).and_return(tmp("tags.txt", false)) @tag = SpecTag.new "fail(broken):Some#method works" end @@ -478,20 +477,20 @@ describe MSpec, ".write_tag" do it "writes a tag to the tags file for the current spec file" do MSpec.write_tag @tag - IO.read(tmp("tags.txt", false)).should == "fail(broken):Some#method works\n" + expect(IO.read(tmp("tags.txt", false))).to eq("fail(broken):Some#method works\n") end it "does not write a duplicate tag" do File.open(tmp("tags.txt", false), "w") { |f| f.puts @tag } MSpec.write_tag @tag - IO.read(tmp("tags.txt", false)).should == "fail(broken):Some#method works\n" + expect(IO.read(tmp("tags.txt", false))).to eq("fail(broken):Some#method works\n") end end -describe MSpec, ".delete_tag" do +RSpec.describe MSpec, ".delete_tag" do before :each do FileUtils.cp File.dirname(__FILE__) + "/tags.txt", tmp("tags.txt", false) - MSpec.stub(:tags_file).and_return(tmp("tags.txt", false)) + allow(MSpec).to receive(:tags_file).and_return(tmp("tags.txt", false)) @tag = SpecTag.new "fail(Comments don't matter):Some#method? works" end @@ -500,84 +499,84 @@ describe MSpec, ".delete_tag" do end it "deletes the tag if it exists" do - MSpec.delete_tag(@tag).should == true - IO.read(tmp("tags.txt", false)).should == %[incomplete(20%):The#best method ever + expect(MSpec.delete_tag(@tag)).to eq(true) + expect(IO.read(tmp("tags.txt", false))).to eq(%[incomplete(20%):The#best method ever benchmark(0.01825):The#fastest method today extended():\"Multi-line\\ntext\\ntag\" -] +]) end it "deletes a tag with escaped newlines" do - MSpec.delete_tag(SpecTag.new('extended:"Multi-line\ntext\ntag"')).should == true - IO.read(tmp("tags.txt", false)).should == %[fail(broken):Some#method? works + expect(MSpec.delete_tag(SpecTag.new('extended:"Multi-line\ntext\ntag"'))).to eq(true) + expect(IO.read(tmp("tags.txt", false))).to eq(%[fail(broken):Some#method? works incomplete(20%):The#best method ever benchmark(0.01825):The#fastest method today -] +]) end it "does not change the tags file contents if the tag doesn't exist" do @tag.tag = "failed" - MSpec.delete_tag(@tag).should == false - IO.read(tmp("tags.txt", false)).should == %[fail(broken):Some#method? works + expect(MSpec.delete_tag(@tag)).to eq(false) + expect(IO.read(tmp("tags.txt", false))).to eq(%[fail(broken):Some#method? works incomplete(20%):The#best method ever benchmark(0.01825):The#fastest method today extended():\"Multi-line\\ntext\\ntag\" -] +]) end it "deletes the tag file if it is empty" do - MSpec.delete_tag(@tag).should == true - MSpec.delete_tag(SpecTag.new("incomplete:The#best method ever")).should == true - MSpec.delete_tag(SpecTag.new("benchmark:The#fastest method today")).should == true - MSpec.delete_tag(SpecTag.new('extended:"Multi-line\ntext\ntag"')).should == true - File.exist?(tmp("tags.txt", false)).should == false + expect(MSpec.delete_tag(@tag)).to eq(true) + expect(MSpec.delete_tag(SpecTag.new("incomplete:The#best method ever"))).to eq(true) + expect(MSpec.delete_tag(SpecTag.new("benchmark:The#fastest method today"))).to eq(true) + expect(MSpec.delete_tag(SpecTag.new('extended:"Multi-line\ntext\ntag"'))).to eq(true) + expect(File.exist?(tmp("tags.txt", false))).to eq(false) end end -describe MSpec, ".delete_tags" do +RSpec.describe MSpec, ".delete_tags" do before :each do @tags = tmp("tags.txt", false) FileUtils.cp File.dirname(__FILE__) + "/tags.txt", @tags - MSpec.stub(:tags_file).and_return(@tags) + allow(MSpec).to receive(:tags_file).and_return(@tags) end it "deletes the tag file" do MSpec.delete_tags - File.exist?(@tags).should be_false + expect(File.exist?(@tags)).to be_falsey end end -describe MSpec, ".expectation" do +RSpec.describe MSpec, ".expectation" do it "sets the flag that an expectation has been reported" do MSpec.clear_expectations - MSpec.expectation?.should be_false + expect(MSpec.expectation?).to be_falsey MSpec.expectation - MSpec.expectation?.should be_true + expect(MSpec.expectation?).to be_truthy end end -describe MSpec, ".expectation?" do +RSpec.describe MSpec, ".expectation?" do it "returns true if an expectation has been reported" do MSpec.expectation - MSpec.expectation?.should be_true + expect(MSpec.expectation?).to be_truthy end it "returns false if an expectation has not been reported" do MSpec.clear_expectations - MSpec.expectation?.should be_false + expect(MSpec.expectation?).to be_falsey end end -describe MSpec, ".clear_expectations" do +RSpec.describe MSpec, ".clear_expectations" do it "clears the flag that an expectation has been reported" do MSpec.expectation - MSpec.expectation?.should be_true + expect(MSpec.expectation?).to be_truthy MSpec.clear_expectations - MSpec.expectation?.should be_false + expect(MSpec.expectation?).to be_falsey end end -describe MSpec, ".register_shared" do +RSpec.describe MSpec, ".register_shared" do it "stores a shared ContextState by description" do parent = ContextState.new "container" state = ContextState.new "shared" @@ -585,14 +584,14 @@ describe MSpec, ".register_shared" do prc = lambda { } state.describe(&prc) MSpec.register_shared(state) - MSpec.retrieve(:shared)["shared"].should == state + expect(MSpec.retrieve(:shared)["shared"]).to eq(state) end end -describe MSpec, ".retrieve_shared" do +RSpec.describe MSpec, ".retrieve_shared" do it "retrieves the shared ContextState matching description" do state = ContextState.new "" MSpec.retrieve(:shared)["shared"] = state - MSpec.retrieve_shared(:shared).should == state + expect(MSpec.retrieve_shared(:shared)).to eq(state) end end diff --git a/spec/mspec/spec/runner/shared_spec.rb b/spec/mspec/spec/runner/shared_spec.rb index b91800b7db..153b8f0698 100644 --- a/spec/mspec/spec/runner/shared_spec.rb +++ b/spec/mspec/spec/runner/shared_spec.rb @@ -3,7 +3,7 @@ require 'mspec/runner/shared' require 'mspec/runner/context' require 'mspec/runner/example' -describe Object, "#it_behaves_like" do +RSpec.describe Object, "#it_behaves_like" do before :each do ScratchPad.clear @@ -14,14 +14,14 @@ describe Object, "#it_behaves_like" do @state.singleton_class.send(:public, :it_behaves_like) @shared = ContextState.new :shared_spec, :shared => true - MSpec.stub(:retrieve_shared).and_return(@shared) + allow(MSpec).to receive(:retrieve_shared).and_return(@shared) end it "creates @method set to the name of the aliased method" do @shared.it("an example") { ScratchPad.record @method } @state.it_behaves_like :shared_spec, :some_method @state.process - ScratchPad.recorded.should == :some_method + expect(ScratchPad.recorded).to eq(:some_method) end it "creates @object if the passed object" do @@ -29,7 +29,7 @@ describe Object, "#it_behaves_like" do @shared.it("an example") { ScratchPad.record @object } @state.it_behaves_like :shared_spec, :some_method, object @state.process - ScratchPad.recorded.should == object + expect(ScratchPad.recorded).to eq(object) end it "creates @object if the passed false" do @@ -37,11 +37,11 @@ describe Object, "#it_behaves_like" do @shared.it("an example") { ScratchPad.record @object } @state.it_behaves_like :shared_spec, :some_method, object @state.process - ScratchPad.recorded.should == object + expect(ScratchPad.recorded).to eq(object) end it "sends :it_should_behave_like" do - @state.should_receive(:it_should_behave_like) + expect(@state).to receive(:it_should_behave_like) @state.it_behaves_like :shared_spec, :some_method end @@ -61,12 +61,12 @@ describe Object, "#it_behaves_like" do @state.it_behaves_like :shared_spec, :some_method, @obj @state.process - ScratchPad.recorded.should == [:some_method, @obj] + expect(ScratchPad.recorded).to eq([:some_method, @obj]) @state2.it_behaves_like :shared_spec, :another_method, @obj2 @state2.process - ScratchPad.recorded.should == [:another_method, @obj2] + expect(ScratchPad.recorded).to eq([:another_method, @obj2]) end it "ensures the shared spec state is distinct for nested shared specs" do @@ -79,12 +79,12 @@ describe Object, "#it_behaves_like" do @state.it_behaves_like :shared_spec, :some_method, @obj @state.process - ScratchPad.recorded.should == [:shared, :some_method, @obj] + expect(ScratchPad.recorded).to eq([:shared, :some_method, @obj]) @state2.it_behaves_like :shared_spec, :another_method, @obj2 @state2.process - ScratchPad.recorded.should == [:shared, :another_method, @obj2] + expect(ScratchPad.recorded).to eq([:shared, :another_method, @obj2]) end end end diff --git a/spec/mspec/spec/runner/tag_spec.rb b/spec/mspec/spec/runner/tag_spec.rb index db55a1b186..bda9ac4280 100644 --- a/spec/mspec/spec/runner/tag_spec.rb +++ b/spec/mspec/spec/runner/tag_spec.rb @@ -1,123 +1,123 @@ require 'spec_helper' require 'mspec/runner/tag' -describe SpecTag do +RSpec.describe SpecTag do it "accepts an optional string to parse into fields" do tag = SpecTag.new "tag(comment):description" - tag.tag.should == "tag" - tag.comment.should == "comment" - tag.description.should == "description" + expect(tag.tag).to eq("tag") + expect(tag.comment).to eq("comment") + expect(tag.description).to eq("description") end end -describe SpecTag, "#parse" do +RSpec.describe SpecTag, "#parse" do before :each do @tag = SpecTag.new end it "accepts 'tag(comment):description'" do @tag.parse "tag(I'm real):Some#method returns a value" - @tag.tag.should == "tag" - @tag.comment.should == "I'm real" - @tag.description.should == "Some#method returns a value" + expect(@tag.tag).to eq("tag") + expect(@tag.comment).to eq("I'm real") + expect(@tag.description).to eq("Some#method returns a value") end it "accepts 'tag:description'" do @tag.parse "tag:Another#method" - @tag.tag.should == "tag" - @tag.comment.should == nil - @tag.description.should == "Another#method" + expect(@tag.tag).to eq("tag") + expect(@tag.comment).to eq(nil) + expect(@tag.description).to eq("Another#method") end it "accepts 'tag():description'" do @tag.parse "tag():Another#method" - @tag.tag.should == "tag" - @tag.comment.should == nil - @tag.description.should == "Another#method" + expect(@tag.tag).to eq("tag") + expect(@tag.comment).to eq(nil) + expect(@tag.description).to eq("Another#method") end it "accepts 'tag:'" do @tag.parse "tag:" - @tag.tag.should == "tag" - @tag.comment.should == nil - @tag.description.should == "" + expect(@tag.tag).to eq("tag") + expect(@tag.comment).to eq(nil) + expect(@tag.description).to eq("") end it "accepts 'tag(bug:555):Another#method'" do @tag.parse "tag(bug:555):Another#method" - @tag.tag.should == "tag" - @tag.comment.should == "bug:555" - @tag.description.should == "Another#method" + expect(@tag.tag).to eq("tag") + expect(@tag.comment).to eq("bug:555") + expect(@tag.description).to eq("Another#method") end it "accepts 'tag(http://someplace.com/neato):Another#method'" do @tag.parse "tag(http://someplace.com/neato):Another#method" - @tag.tag.should == "tag" - @tag.comment.should == "http://someplace.com/neato" - @tag.description.should == "Another#method" + expect(@tag.tag).to eq("tag") + expect(@tag.comment).to eq("http://someplace.com/neato") + expect(@tag.description).to eq("Another#method") end it "accepts 'tag(comment):\"Multi-line\\ntext\"'" do @tag.parse 'tag(comment):"Multi-line\ntext"' - @tag.tag.should == "tag" - @tag.comment.should == "comment" - @tag.description.should == "Multi-line\ntext" + expect(@tag.tag).to eq("tag") + expect(@tag.comment).to eq("comment") + expect(@tag.description).to eq("Multi-line\ntext") end it "ignores '#anything'" do @tag.parse "# this could be a comment" - @tag.tag.should == nil - @tag.comment.should == nil - @tag.description.should == nil + expect(@tag.tag).to eq(nil) + expect(@tag.comment).to eq(nil) + expect(@tag.description).to eq(nil) end end -describe SpecTag, "#to_s" do +RSpec.describe SpecTag, "#to_s" do it "formats itself as 'tag(comment):description'" do txt = "tag(comment):description" tag = SpecTag.new txt - tag.tag.should == "tag" - tag.comment.should == "comment" - tag.description.should == "description" - tag.to_s.should == txt + expect(tag.tag).to eq("tag") + expect(tag.comment).to eq("comment") + expect(tag.description).to eq("description") + expect(tag.to_s).to eq(txt) end it "formats itself as 'tag:description" do txt = "tag:description" tag = SpecTag.new txt - tag.tag.should == "tag" - tag.comment.should == nil - tag.description.should == "description" - tag.to_s.should == txt + expect(tag.tag).to eq("tag") + expect(tag.comment).to eq(nil) + expect(tag.description).to eq("description") + expect(tag.to_s).to eq(txt) end it "formats itself as 'tag(comment):\"multi-line\\ntext\\ntag\"'" do txt = 'tag(comment):"multi-line\ntext\ntag"' tag = SpecTag.new txt - tag.tag.should == "tag" - tag.comment.should == "comment" - tag.description.should == "multi-line\ntext\ntag" - tag.to_s.should == txt + expect(tag.tag).to eq("tag") + expect(tag.comment).to eq("comment") + expect(tag.description).to eq("multi-line\ntext\ntag") + expect(tag.to_s).to eq(txt) end end -describe SpecTag, "#==" do +RSpec.describe SpecTag, "#==" do it "returns true if the tags have the same fields" do one = SpecTag.new "tag(this):unicorn" two = SpecTag.new "tag(this):unicorn" - one.==(two).should == true - [one].==([two]).should == true + expect(one.==(two)).to eq(true) + expect([one].==([two])).to eq(true) end end -describe SpecTag, "#unescape" do +RSpec.describe SpecTag, "#unescape" do it "replaces \\n by LF when the description is quoted" do tag = SpecTag.new 'tag:"desc with\nnew line"' - tag.description.should == "desc with\nnew line" + expect(tag.description).to eq("desc with\nnew line") end it "does not replaces \\n by LF when the description is not quoted " do tag = SpecTag.new 'tag:desc with\nnew line' - tag.description.should == "desc with\\nnew line" + expect(tag.description).to eq("desc with\\nnew line") end end |