1 require File.dirname(__FILE__) + '/../spec_helper'
2 require 'mspec/utils/script'
3 require 'mspec/runner/mspec'
4 require 'mspec/runner/filters'
5 require 'mspec/runner/actions/filter'
6 require 'mspec/runner/actions/debug'
7 require 'mspec/runner/actions/gdb'
9 describe MSpecScript, ".config" do
10 it "returns a Hash" do
11 MSpecScript.config.should be_kind_of(Hash)
15 describe MSpecScript, ".set" do
16 it "sets the config hash key, value" do
17 MSpecScript.set :a, 10
18 MSpecScript.config[:a].should == 10
22 describe MSpecScript, "#config" do
23 it "returns the MSpecScript config hash" do
25 MSpecScript.new.config[:b].should == 5
28 it "returns the MSpecScript config hash from subclasses" do
29 class MSSClass < MSpecScript; end
31 MSSClass.new.config[:b].should == 5
35 describe MSpecScript, ".main" do
37 @script = mock("MSpecScript", :null_object => true)
38 MSpecScript.stub!(:new).and_return(@script)
41 it "creates an instance of MSpecScript" do
42 MSpecScript.should_receive(:new).and_return(@script)
46 it "attempts to load the 'default.mspec' script" do
47 @script.should_receive(:load).with('default.mspec')
51 it "attempts to load the '~/.mspecrc' script" do
52 @script.should_receive(:load).with('~/.mspecrc')
56 it "calls the #options method on the script" do
57 @script.should_receive(:options)
61 it "calls the #signals method on the script" do
62 @script.should_receive(:signals)
66 it "calls the #register method on the script" do
67 @script.should_receive(:register)
71 it "calls the #run method on the script" do
72 @script.should_receive(:run)
77 describe MSpecScript, "#initialize" do
79 @config = MSpecScript.new.config
82 it "sets the default config values" do
83 @config[:tags_dir].should == 'spec/tags'
84 @config[:formatter].should == DottedFormatter
85 @config[:includes].should == []
86 @config[:excludes].should == []
87 @config[:patterns].should == []
88 @config[:xpatterns].should == []
89 @config[:tags].should == []
90 @config[:xtags].should == []
91 @config[:atags].should == []
92 @config[:astrings].should == []
93 @config[:abort].should == true
94 @config[:config_ext].should == '.mspec'
98 describe MSpecScript, "#load" do
100 File.stub!(:exist?).and_return(false)
101 @script = MSpecScript.new
102 @file = "default.mspec"
106 it "attempts to locate the file through the expanded path name" do
107 File.should_receive(:expand_path).with(@file).and_return(@file)
108 File.should_receive(:exist?).with(@file).and_return(true)
109 Kernel.should_receive(:load).with(@file).and_return(:loaded)
110 @script.load(@file).should == :loaded
113 it "appends config[:config_ext] to the name and attempts to locate the file through the expanded path name" do
114 File.should_receive(:expand_path).with(@base).and_return(@base)
115 File.should_receive(:expand_path).with(@file).and_return(@file)
116 File.should_receive(:exist?).with(@base).and_return(false)
117 File.should_receive(:exist?).with(@file).and_return(true)
118 Kernel.should_receive(:load).with(@file).and_return(:loaded)
119 @script.load(@base).should == :loaded
122 it "attemps to locate the file in '.'" do
123 path = File.join ".", @file
124 File.should_receive(:exist?).with(path).and_return(true)
125 Kernel.should_receive(:load).with(path).and_return(:loaded)
126 @script.load(@file).should == :loaded
129 it "appends config[:config_ext] to the name and attempts to locate the file in '.'" do
130 path = File.join ".", @file
131 File.should_receive(:exist?).with(path).and_return(true)
132 Kernel.should_receive(:load).with(path).and_return(:loaded)
133 @script.load(@base).should == :loaded
136 it "attemps to locate the file in 'spec'" do
137 path = File.join "spec", @file
138 File.should_receive(:exist?).with(path).and_return(true)
139 Kernel.should_receive(:load).with(path).and_return(:loaded)
140 @script.load(@file).should == :loaded
143 it "appends config[:config_ext] to the name and attempts to locate the file in 'spec'" do
144 path = File.join "spec", @file
145 File.should_receive(:exist?).with(path).and_return(true)
146 Kernel.should_receive(:load).with(path).and_return(:loaded)
147 @script.load(@base).should == :loaded
151 describe MSpecScript, "#register" do
153 @script = MSpecScript.new
155 @formatter = mock("formatter", :null_object => true)
156 @script.config[:formatter] = @formatter
159 it "creates and registers the formatter" do
160 @formatter.should_receive(:new).and_return(@formatter)
161 @formatter.should_receive(:register)
166 describe MSpecScript, "#register" do
168 @script = MSpecScript.new
170 @formatter = mock("formatter", :null_object => true)
171 @script.config[:formatter] = @formatter
173 @filter = mock("filter")
174 @filter.should_receive(:register)
176 @ary = ["some", "spec"]
179 it "creates and registers a MatchFilter for include specs" do
180 MatchFilter.should_receive(:new).with(:include, *@ary).and_return(@filter)
181 @script.config[:includes] = @ary
185 it "creates and registers a MatchFilter for excluded specs" do
186 MatchFilter.should_receive(:new).with(:exclude, *@ary).and_return(@filter)
187 @script.config[:excludes] = @ary
191 it "creates and registers a RegexpFilter for include specs" do
192 RegexpFilter.should_receive(:new).with(:include, *@ary).and_return(@filter)
193 @script.config[:patterns] = @ary
197 it "creates and registers a RegexpFilter for excluded specs" do
198 RegexpFilter.should_receive(:new).with(:exclude, *@ary).and_return(@filter)
199 @script.config[:xpatterns] = @ary
203 it "creates and registers a TagFilter for include specs" do
204 TagFilter.should_receive(:new).with(:include, *@ary).and_return(@filter)
205 @script.config[:tags] = @ary
209 it "creates and registers a TagFilter for excluded specs" do
210 TagFilter.should_receive(:new).with(:exclude, *@ary).and_return(@filter)
211 @script.config[:xtags] = @ary
215 it "creates and registers a ProfileFilter for include specs" do
216 ProfileFilter.should_receive(:new).with(:include, *@ary).and_return(@filter)
217 @script.config[:profiles] = @ary
221 it "creates and registers a ProfileFilter for excluded specs" do
222 ProfileFilter.should_receive(:new).with(:exclude, *@ary).and_return(@filter)
223 @script.config[:xprofiles] = @ary
227 it "creates and registers a DebugAction for excluded specs" do
228 @script.config[:atags] = ["some"]
229 @script.config[:astrings] = ["string"]
230 DebugAction.should_receive(:new).with(["some"], ["string"]).and_return(@filter)
231 @script.config[:debugger] = true
235 it "creates and registers a GdbAction for excluded specs" do
236 @script.config[:atags] = ["some"]
237 @script.config[:astrings] = ["string"]
238 GdbAction.should_receive(:new).with(["some"], ["string"]).and_return(@filter)
239 @script.config[:gdb] = true
244 describe MSpecScript, "#signals" do
246 @script = MSpecScript.new
247 @abort = @script.config[:abort]
251 @script.config[:abort] = @abort
254 it "traps the INT signal if config[:abort] is true" do
255 Signal.should_receive(:trap).with("INT")
256 @script.config[:abort] = true
260 it "does not trap the INT signal if config[:abort] is not true" do
261 Signal.should_not_receive(:trap).with("INT")
262 @script.config[:abort] = false