diff options
Diffstat (limited to 'spec/mspec/spec/runner/filters')
-rw-r--r-- | spec/mspec/spec/runner/filters/a.yaml | 4 | ||||
-rw-r--r-- | spec/mspec/spec/runner/filters/b.yaml | 11 | ||||
-rw-r--r-- | spec/mspec/spec/runner/filters/match_spec.rb | 34 | ||||
-rw-r--r-- | spec/mspec/spec/runner/filters/profile_spec.rb | 117 | ||||
-rw-r--r-- | spec/mspec/spec/runner/filters/regexp_spec.rb | 13 | ||||
-rw-r--r-- | spec/mspec/spec/runner/filters/tag_spec.rb | 92 |
6 files changed, 271 insertions, 0 deletions
diff --git a/spec/mspec/spec/runner/filters/a.yaml b/spec/mspec/spec/runner/filters/a.yaml new file mode 100644 index 0000000000..1940e3cba6 --- /dev/null +++ b/spec/mspec/spec/runner/filters/a.yaml @@ -0,0 +1,4 @@ +--- +A#: +- a +- aa diff --git a/spec/mspec/spec/runner/filters/b.yaml b/spec/mspec/spec/runner/filters/b.yaml new file mode 100644 index 0000000000..a24bdb2f19 --- /dev/null +++ b/spec/mspec/spec/runner/filters/b.yaml @@ -0,0 +1,11 @@ +--- +B.: +- b +- bb +B::C#: +- b! +- b= +- b? +- "-" +- "[]" +- "[]=" diff --git a/spec/mspec/spec/runner/filters/match_spec.rb b/spec/mspec/spec/runner/filters/match_spec.rb new file mode 100644 index 0000000000..f2c665c495 --- /dev/null +++ b/spec/mspec/spec/runner/filters/match_spec.rb @@ -0,0 +1,34 @@ +require File.dirname(__FILE__) + '/../../spec_helper' +require 'mspec/runner/mspec' +require 'mspec/runner/filters/match' + +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 + end + + it "returns false if the argument matches none of the #initialize strings" do + @filter.===('d').should == false + end +end + +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) + filter.register + end +end + +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) + filter.unregister + end +end diff --git a/spec/mspec/spec/runner/filters/profile_spec.rb b/spec/mspec/spec/runner/filters/profile_spec.rb new file mode 100644 index 0000000000..78807bca5c --- /dev/null +++ b/spec/mspec/spec/runner/filters/profile_spec.rb @@ -0,0 +1,117 @@ +require File.dirname(__FILE__) + '/../../spec_helper' +require 'mspec/runner/mspec' +require 'mspec/runner/filters/profile' + +describe ProfileFilter, "#find" do + before :each do + @filter = ProfileFilter.new nil + File.stub(: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 + end + + it "attemps 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 + end + + it "attemps 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 + end + + it "attemps 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 + end + + it "attemps to locate the file in '.'" do + path = File.join ".", @file + File.should_receive(:exist?).with(path).and_return(true) + @filter.find(@file).should == path + end +end + +describe ProfileFilter, "#parse" do + before :each do + @filter = ProfileFilter.new nil + @file = File.open(File.dirname(__FILE__) + "/b.yaml", "r") + end + + after :each do + @file.close + end + + it "creates a Hash of the contents of the YAML file" do + @filter.parse(@file).should == { + "B." => ["b", "bb"], + "B::C#" => ["b!", "b=", "b?", "-", "[]", "[]="] + } + end +end + +describe ProfileFilter, "#load" do + before :each do + @filter = ProfileFilter.new nil + @files = [ + File.dirname(__FILE__) + "/a.yaml", + File.dirname(__FILE__) + "/b.yaml" + ] + end + + it "generates a composite hash from multiple YAML files" do + @filter.load(*@files).should == { + "A#" => ["a", "aa"], + "B." => ["b", "bb"], + "B::C#" => ["b!", "b=", "b?", "-", "[]", "[]="] + } + end +end + +describe ProfileFilter, "#===" do + before :each do + @filter = ProfileFilter.new nil + @filter.stub(: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 + 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 + end +end + +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) + filter.register + end +end + +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) + filter.unregister + end +end diff --git a/spec/mspec/spec/runner/filters/regexp_spec.rb b/spec/mspec/spec/runner/filters/regexp_spec.rb new file mode 100644 index 0000000000..6c05b0f42f --- /dev/null +++ b/spec/mspec/spec/runner/filters/regexp_spec.rb @@ -0,0 +1,13 @@ +require File.dirname(__FILE__) + '/../../spec_helper' +require 'mspec/runner/mspec' +require 'mspec/runner/filters/regexp' + +describe RegexpFilter, "#to_regexp" do + before :each do + @filter = RegexpFilter.new nil + end + + it "converts its arguments to Regexp instances" do + @filter.to_regexp('a(b|c)', 'b[^ab]', 'cc?').should == [/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 new file mode 100644 index 0000000000..fe1f3df039 --- /dev/null +++ b/spec/mspec/spec/runner/filters/tag_spec.rb @@ -0,0 +1,92 @@ +require File.dirname(__FILE__) + '/../../spec_helper' +require 'mspec/runner/mspec' +require 'mspec/runner/filters/match' +require 'mspec/runner/filters/tag' + +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) + end + + it "loads tags from the tag file" do + MSpec.should_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) + filter.load + end + + it "registers itself with MSpec for the :exclude action" do + filter = TagFilter.new(:exclude) + MSpec.should_receive(:register).with(:exclude, filter) + filter.load + end +end + +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) + end + + it "unregisters itself" do + @filter.load + MSpec.should_receive(:unregister).with(:include, @filter) + @filter.unload + end +end + +describe TagFilter, "#register" do + before :each do + MSpec.stub(: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) + filter.register + end +end + +describe TagFilter, "#unregister" do + before :each do + MSpec.stub(: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) + filter.unregister + end +end + +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) + @filter.load + end + + it "returns true if the argument matches any of the descriptions" do + @filter.===('description').should == true + end + + it "returns false if the argument matches none of the descriptions" do + @filter.===('descriptionA').should == false + @filter.===('adescription').should == false + end +end |