Updated MSpec source to 1c801cd6.
[rbx.git] / mspec / spec / utils / script_spec.rb
blobbc981188caa83192e4dce92f5cb2eddee88b4b5b
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)
12   end
13 end
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
19   end
20 end
22 describe MSpecScript, "#config" do
23   it "returns the MSpecScript config hash" do
24     MSpecScript.set :b, 5
25     MSpecScript.new.config[:b].should == 5
26   end
28   it "returns the MSpecScript config hash from subclasses" do
29     class MSSClass < MSpecScript; end
30     MSpecScript.set :b, 5
31     MSSClass.new.config[:b].should == 5
32   end
33 end
35 describe MSpecScript, ".main" do
36   before :each do
37     @script = mock("MSpecScript", :null_object => true)
38     MSpecScript.stub!(:new).and_return(@script)
39   end
41   it "creates an instance of MSpecScript" do
42     MSpecScript.should_receive(:new).and_return(@script)
43     MSpecScript.main
44   end
46   it "attempts to load the 'default.mspec' script" do
47     @script.should_receive(:load).with('default.mspec')
48     MSpecScript.main
49   end
51   it "attempts to load the '~/.mspecrc' script" do
52     @script.should_receive(:load).with('~/.mspecrc')
53     MSpecScript.main
54   end
56   it "calls the #options method on the script" do
57     @script.should_receive(:options)
58     MSpecScript.main
59   end
61   it "calls the #signals method on the script" do
62     @script.should_receive(:signals)
63     MSpecScript.main
64   end
66   it "calls the #register method on the script" do
67     @script.should_receive(:register)
68     MSpecScript.main
69   end
71   it "calls the #run method on the script" do
72     @script.should_receive(:run)
73     MSpecScript.main
74   end
75 end
77 describe MSpecScript, "#initialize" do
78   before :each do
79     @config = MSpecScript.new.config
80   end
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'
95   end
96 end
98 describe MSpecScript, "#load" do
99   before :each do
100     File.stub!(:exist?).and_return(false)
101     @script = MSpecScript.new
102     @file = "default.mspec"
103     @base = "default"
104   end
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
111   end
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
120   end
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
127   end
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
134   end
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
141   end
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
148   end
151 describe MSpecScript, "#register" do
152   before :each do
153     @script = MSpecScript.new
155     @formatter = mock("formatter", :null_object => true)
156     @script.config[:formatter] = @formatter
157   end
159   it "creates and registers the formatter" do
160     @formatter.should_receive(:new).and_return(@formatter)
161     @formatter.should_receive(:register)
162     @script.register
163   end
166 describe MSpecScript, "#register" do
167   before :each 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"]
177   end
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
182     @script.register
183   end
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
188     @script.register
189   end
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
194     @script.register
195   end
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
200     @script.register
201   end
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
206     @script.register
207   end
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
212     @script.register
213   end
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
218     @script.register
219   end
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
224     @script.register
225   end
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
232     @script.register
233   end
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
240     @script.register
241   end
244 describe MSpecScript, "#signals" do
245   before :each do
246     @script = MSpecScript.new
247     @abort = @script.config[:abort]
248   end
250   after :each do
251     @script.config[:abort] = @abort
252   end
254   it "traps the INT signal if config[:abort] is true" do
255     Signal.should_receive(:trap).with("INT")
256     @script.config[:abort] = true
257     @script.signals
258   end
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
263     @script.signals
264   end