diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-07 12:04:49 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-07 12:04:49 +0000 |
commit | 95e8c48dd3348503a8c7db5d0498894a1b676395 (patch) | |
tree | 9eef7f720314ebaff56845a74e203770e62284e4 /spec/mspec/spec/runner/actions/tagpurge_spec.rb | |
parent | ed7d803500de38186c74bce94d233e85ef51e503 (diff) |
Add in-tree mspec and ruby/spec
* For easier modifications of ruby/spec by MRI developers.
* .gitignore: track changes under spec.
* spec/mspec, spec/rubyspec: add in-tree mspec and ruby/spec.
These files can therefore be updated like any other file in MRI.
Instructions are provided in spec/README.
[Feature #13156] [ruby-core:79246]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/mspec/spec/runner/actions/tagpurge_spec.rb')
-rw-r--r-- | spec/mspec/spec/runner/actions/tagpurge_spec.rb | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/spec/mspec/spec/runner/actions/tagpurge_spec.rb b/spec/mspec/spec/runner/actions/tagpurge_spec.rb new file mode 100644 index 0000000000..27ad2a1470 --- /dev/null +++ b/spec/mspec/spec/runner/actions/tagpurge_spec.rb @@ -0,0 +1,154 @@ +require File.dirname(__FILE__) + '/../../spec_helper' +require 'mspec/runner/actions/tagpurge' +require 'mspec/runner/mspec' +require 'mspec/runner/example' +require 'mspec/runner/tag' + +describe TagPurgeAction, "#start" do + before :each do + @stdout = $stdout + $stdout = IOStub.new + end + + after :each do + $stdout = @stdout + end + + it "prints a banner" do + action = TagPurgeAction.new + action.start + $stdout.should == "\nRemoving tags not matching any specs\n\n" + end +end + +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") + TagPurgeAction.new.load + end +end + +describe TagPurgeAction, "#after" do + before :each do + @state = double("ExampleState") + @state.stub(: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) + @action.after @state + @action.matching.should == [] + end + + it "saves the description if the filter matches" do + @action.should_receive(:===).with("str").and_return(true) + @action.after @state + @action.matching.should == ["str"] + end +end + +describe TagPurgeAction, "#unload" do + before :each do + @stdout = $stdout + $stdout = IOStub.new + + @t1 = SpecTag.new "fails:I fail" + @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) + + @state = double("ExampleState") + @state.stub(:description).and_return("I'm unstable") + + @action = TagPurgeAction.new + @action.load + @action.after @state + end + + after :each do + $stdout = @stdout + 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) + + @action.load + @action.after @state + @action.unload + + $stdout.should == "" + end + + it "rewrites tags that were matched" do + MSpec.should_receive(:write_tags).with([@t2, @t3]) + @action.unload + end + + it "prints tags that were not matched" do + @action.unload + $stdout.should == "I fail\n" + end +end + +describe TagPurgeAction, "#unload" do + before :each do + @stdout = $stdout + $stdout = IOStub.new + + MSpec.stub(:read_tags).and_return([]) + + @state = double("ExampleState") + @state.stub(:description).and_return("I'm unstable") + + @action = TagPurgeAction.new + @action.load + @action.after @state + end + + after :each do + $stdout = @stdout + end + + it "deletes the tag file if no tags were found" do + MSpec.should_not_receive(:write_tags) + MSpec.should_receive(:delete_tags) + @action.unload + $stdout.should == "" + end +end + +describe TagPurgeAction, "#register" do + before :each do + MSpec.stub(:register) + @action = TagPurgeAction.new + end + + it "registers itself with MSpec for the :unload event" do + MSpec.should_receive(:register).with(:unload, @action) + @action.register + end +end + +describe TagPurgeAction, "#unregister" do + before :each do + MSpec.stub(:unregister) + @action = TagPurgeAction.new + end + + it "unregisters itself with MSpec for the :unload event" do + MSpec.should_receive(:unregister).with(:unload, @action) + @action.unregister + end +end |