mspec 1.5.3 → 1.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -66,6 +66,9 @@ class MSpecTag < MSpecScript
66
66
  options.on("--list-all", "Display descriptions of any tagged specs") do
67
67
  config[:tagger] = :list_all
68
68
  end
69
+ options.on("--purge", "Remove all tags not matching any specs") do
70
+ config[:tagger] = :purge
71
+ end
69
72
 
70
73
  options.doc "\n Help!"
71
74
  options.version MSpec::VERSION
@@ -99,6 +102,10 @@ class MSpecTag < MSpecScript
99
102
  tagger = TagListAction.new config[:tagger] == :list_all ? nil : config[:ltags]
100
103
  MSpec.register_mode :pretend
101
104
  config[:formatter] = false
105
+ when :purge
106
+ tagger = TagPurgeAction.new
107
+ MSpec.register_mode :pretend
108
+ config[:formatter] = false
102
109
  else
103
110
  raise ArgumentError, "No recognized action given"
104
111
  end
@@ -10,7 +10,7 @@ class BigEndianGuard < SpecGuard
10
10
  private :pattern
11
11
 
12
12
  def match?
13
- pattern[-1] == 1
13
+ pattern[-1] == ?\001
14
14
  end
15
15
  end
16
16
 
@@ -21,7 +21,7 @@ class LittleEndianGuard < SpecGuard
21
21
  private :pattern
22
22
 
23
23
  def match?
24
- pattern[-1] == 0
24
+ pattern[-1] == ?\000
25
25
  end
26
26
  end
27
27
 
data/lib/mspec/helpers.rb CHANGED
@@ -5,4 +5,5 @@ require 'mspec/helpers/scratch'
5
5
  require 'mspec/helpers/tmp'
6
6
  require 'mspec/helpers/const_lookup'
7
7
  require 'mspec/helpers/ruby_exe'
8
- require 'mspec/helpers/metaclass'
8
+ require 'mspec/helpers/fixture'
9
+ require 'mspec/helpers/argv'
@@ -0,0 +1,43 @@
1
+ class Object
2
+ # Convenience helper for altering ARGV. Saves the
3
+ # value of ARGV and sets it to +args+. If a block
4
+ # is given, yields to the block and then restores
5
+ # the value of ARGV. The previously saved value of
6
+ # ARGV can be restored by passing +:restore+. The
7
+ # former is useful in a single spec. The latter is
8
+ # useful in before/after actions. For example:
9
+ #
10
+ # describe "This" do
11
+ # before do
12
+ # argv ['a', 'b']
13
+ # end
14
+ #
15
+ # after do
16
+ # argv :restore
17
+ # end
18
+ #
19
+ # it "does something" do
20
+ # # do something
21
+ # end
22
+ # end
23
+ #
24
+ # describe "That" do
25
+ # it "does something" do
26
+ # argv ['a', 'b'] do
27
+ # # do something
28
+ # end
29
+ # end
30
+ # end
31
+ def argv(args)
32
+ if args == :restore
33
+ ARGV.replace(@__mspec_saved_argv__ || [])
34
+ else
35
+ @__mspec_saved_argv__ = ARGV
36
+ ARGV.replace args
37
+ if block_given?
38
+ yield
39
+ argv :restore
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,20 @@
1
+ class Object
2
+ # Returns the name of a fixture file by adjoining the directory
3
+ # of the +dir+ argument with "fixtures" and the contents of the
4
+ # +args+ array. For example,
5
+ #
6
+ # +dir+ == "some/path"
7
+ #
8
+ # and
9
+ #
10
+ # +args+ == ["dir", "file.txt"]
11
+ #
12
+ # then the result is the expanded path of
13
+ #
14
+ # "some/fixtures/dir/file.txt".
15
+ def fixture(dir, *args)
16
+ path = File.dirname(dir)
17
+ path = path[0..-7] if path[-7..-1] == "/shared"
18
+ File.expand_path(File.join(path, "fixtures", args))
19
+ end
20
+ end
@@ -1,5 +1,5 @@
1
1
  class Object
2
- def flunk
3
- Expectation.fail_with "This example", "is a failure"
2
+ def flunk(msg="This example is a failure")
3
+ Expectation.fail_with "Failed:", msg
4
4
  end
5
5
  end
@@ -21,6 +21,18 @@ require 'mspec/ruby_name'
21
21
  #
22
22
  # `#{RUBY_EXE} -e #{'puts "hello, world."'}`
23
23
  #
24
+ # The ruby_exe helper also accepts an options hash with two
25
+ # keys: :options and :args. For example:
26
+ #
27
+ # ruby_exe('file.rb', :options => "-w", :args => "> file.txt")
28
+ #
29
+ # will be executed as
30
+ #
31
+ # `#{RUBY_EXE} -w #{'file.rb'} > file.txt`
32
+ #
33
+ # If +nil+ is passed for the first argument, the command line
34
+ # will be built only from the options hash.
35
+ #
24
36
  # The RUBY_EXE constant can be set explicitly since the value
25
37
  # is used each time ruby_exe is invoked. The mspec runner script
26
38
  # will set ENV['RUBY_EXE'] to the name of the executable used
@@ -79,17 +91,25 @@ class Object
79
91
  def resolve_ruby_exe
80
92
  [:env, :engine, :name, :install_name].each do |option|
81
93
  exe = ruby_exe_options option
82
- return exe if exe and File.exists?(exe) and File.executable?(exe)
94
+
95
+ # TODO: It has been reported that File.executable is not reliable
96
+ # on Windows platforms (see commit 56bc555c). So, we check the
97
+ # platform. This check is the same as the one used by the guards.
98
+ # This test should be abstracted so it is available in general to
99
+ # MSpec code.
100
+ if exe and File.exists?(exe) and
101
+ (RUBY_PLATFORM.match(/(mswin|mingw)/) || File.executable?(exe))
102
+ return exe
103
+ end
83
104
  end
84
105
  nil
85
106
  end
86
107
 
87
- def ruby_exe(code)
88
- if File.exists?(code)
89
- `#{RUBY_EXE} #{ENV['RUBY_FLAGS']} #{code}`
90
- else
91
- `#{RUBY_EXE} #{ENV['RUBY_FLAGS']} -e #{code.inspect}`
92
- end
108
+ def ruby_exe(code, opts = {})
109
+ body = code
110
+ body = "-e #{code.inspect}" if code and not File.exists?(code)
111
+ cmd = [RUBY_EXE, ENV['RUBY_FLAGS'], opts[:options], body, opts[:args]]
112
+ `#{cmd.compact.join(' ')}`
93
113
  end
94
114
 
95
115
  unless Object.const_defined?(:RUBY_EXE) and RUBY_EXE
@@ -3,5 +3,6 @@ require 'mspec/runner/actions/timer'
3
3
  require 'mspec/runner/actions/filter'
4
4
  require 'mspec/runner/actions/tag'
5
5
  require 'mspec/runner/actions/taglist'
6
+ require 'mspec/runner/actions/tagpurge'
6
7
  require 'mspec/runner/actions/debug'
7
8
  require 'mspec/runner/actions/gdb'
@@ -0,0 +1,56 @@
1
+ require 'mspec/runner/actions/filter'
2
+ require 'mspec/runner/actions/taglist'
3
+
4
+ # TagPurgeAction - removes all tags not matching any spec
5
+ # descriptions.
6
+ class TagPurgeAction < TagListAction
7
+ attr_reader :matching
8
+
9
+ def initialize
10
+ @matching = []
11
+ @filter = nil
12
+ @tags = nil
13
+ end
14
+
15
+ # Prints a banner about purging tags.
16
+ def start
17
+ print "\nRemoving tags not matching any specs\n\n"
18
+ end
19
+
20
+ # Creates a MatchFilter for all tags.
21
+ def load
22
+ @filter = nil
23
+ @tags = MSpec.read_tags self
24
+ desc = @tags.map { |t| t.description }
25
+ @filter = MatchFilter.new(nil, *desc) unless desc.empty?
26
+ end
27
+
28
+ # Saves any matching tags
29
+ def after(state)
30
+ @matching << state.description if self === state.description
31
+ end
32
+
33
+ # Rewrites any matching tags. Prints non-matching tags.
34
+ # Deletes the tag file if there were no tags (this cleans
35
+ # up empty or malformed tag files).
36
+ def unload
37
+ if @filter
38
+ matched = @tags.select { |t| @matching.any? { |s| s == t.description } }
39
+ MSpec.write_tags matched
40
+
41
+ (@tags - matched).each { |t| print t.description, "\n" }
42
+ else
43
+ MSpec.delete_tags
44
+ end
45
+ end
46
+
47
+ def register
48
+ super
49
+ MSpec.register :unload, self
50
+ end
51
+
52
+ def unregister
53
+ super
54
+ MSpec.unregister :unload, self
55
+ end
56
+ end
@@ -245,6 +245,8 @@ module MSpec
245
245
  if File.exist? file
246
246
  File.open(file, "r") do |f|
247
247
  f.each_line do |line|
248
+ line.chomp!
249
+ next if line.empty?
248
250
  tag = SpecTag.new line.chomp
249
251
  tags << tag if keys.include? tag.tag
250
252
  end
@@ -253,11 +255,24 @@ module MSpec
253
255
  tags
254
256
  end
255
257
 
258
+ # Writes each tag in +tags+ to the tag file. Overwrites the
259
+ # tag file if it exists.
260
+ def self.write_tags(tags)
261
+ file = tags_file
262
+ path = File.dirname file
263
+ FileUtils.mkdir_p path unless File.exist? path
264
+ File.open(file, "w") do |f|
265
+ tags.each { |t| f.puts t }
266
+ end
267
+ end
268
+
269
+ # Writes +tag+ to the tag file if it does not already exist.
270
+ # Returns +true+ if the tag is written, +false+ otherwise.
256
271
  def self.write_tag(tag)
257
272
  string = tag.to_s
258
273
  file = tags_file
259
274
  path = File.dirname file
260
- FileUtils.mkdir_p(path) unless File.exist?(path)
275
+ FileUtils.mkdir_p path unless File.exist? path
261
276
  if File.exist? file
262
277
  File.open(file, "r") do |f|
263
278
  f.each_line { |line| return false if line.chomp == string }
@@ -267,6 +282,9 @@ module MSpec
267
282
  return true
268
283
  end
269
284
 
285
+ # Deletes +tag+ from the tag file if it exists. Returns +true+
286
+ # if the tag is deleted, +false+ otherwise. Deletes the tag
287
+ # file if it is empty.
270
288
  def self.delete_tag(tag)
271
289
  deleted = false
272
290
  pattern = /#{tag.tag}.*#{Regexp.escape tag.description}/
@@ -286,4 +304,10 @@ module MSpec
286
304
  end
287
305
  return deleted
288
306
  end
307
+
308
+ # Removes the tag file associated with a spec file.
309
+ def self.delete_tags
310
+ file = tags_file
311
+ File.delete file if File.exists? file
312
+ end
289
313
  end
@@ -116,15 +116,35 @@ class MSpecScript
116
116
  end
117
117
  end
118
118
 
119
- # Resolves +pattern+ as a file name, directory name or pattern.
119
+ # Attempts to resolve +partial+ as a file or directory name in the
120
+ # following order:
121
+ #
122
+ # 1. +partial+
123
+ # 2. +partial+ + "_spec.rb"
124
+ # 3. <tt>File.join(config[:prefix], partial)</tt>
125
+ # 4. <tt>File.join(config[:prefix], partial + "_spec.rb")</tt>
126
+ #
120
127
  # If it is a file name, returns the name as an entry in an array.
121
128
  # If it is a directory, returns all *_spec.rb files in the
122
- # directory and subdirectory. Otherwise, passes +pattern+ to +Dir[]+.
123
- def entries(pattern)
124
- expanded = File.expand_path(pattern)
125
- return [pattern] if File.file?(expanded)
126
- return Dir[pattern+"/**/*_spec.rb"].sort if File.directory?(expanded)
127
- Dir[pattern]
129
+ # directory and subdirectories.
130
+ #
131
+ # If unable to resolve +partial+, returns <tt>Dir[partial]</tt>.
132
+ def entries(partial)
133
+ file = partial + "_spec.rb"
134
+ patterns = [partial]
135
+ patterns << file
136
+ if config[:prefix]
137
+ patterns << File.join(config[:prefix], partial)
138
+ patterns << File.join(config[:prefix], file)
139
+ end
140
+
141
+ patterns.each do |pattern|
142
+ expanded = File.expand_path(pattern)
143
+ return [pattern] if File.file?(expanded)
144
+ return Dir[pattern+"/**/*_spec.rb"].sort if File.directory?(expanded)
145
+ end
146
+
147
+ Dir[partial]
128
148
  end
129
149
 
130
150
  # Resolves each entry in +list+ to a set of files. If the entry
data/lib/mspec/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module MSpec
2
- VERSION = '1.5.3'
2
+ VERSION = '1.5.4'
3
3
  end
@@ -256,7 +256,7 @@ describe MSpecMain, "#run" do
256
256
 
257
257
  it "uses exec to invoke the runner script" do
258
258
  @script.should_receive(:exec).with("ruby", "-v", %r"mspec/bin/mspec-run$")
259
- @script.options
259
+ @script.options []
260
260
  @script.run
261
261
  end
262
262
 
@@ -3,6 +3,7 @@ require 'mspec/runner/mspec'
3
3
  require 'mspec/commands/mspec-tag'
4
4
  require 'mspec/runner/actions/tag'
5
5
  require 'mspec/runner/actions/taglist'
6
+ require 'mspec/runner/actions/tagpurge'
6
7
 
7
8
  describe MSpecTag, ".new" do
8
9
  before :each do
@@ -228,6 +229,20 @@ describe MSpecTag, "options" do
228
229
  @config[:tagger].should == :list_all
229
230
  end
230
231
  end
232
+
233
+ describe "--purge" do
234
+ it "is enabled with #options" do
235
+ @options.stub!(:on)
236
+ @options.should_receive(:on).with("--purge", an_instance_of(String))
237
+ @script.options ["file.rb"]
238
+ end
239
+
240
+ it "sets the mode to :purge" do
241
+ @config[:tagger] = nil
242
+ @script.options ["--purge", "file.rb"]
243
+ @config[:tagger].should == :purge
244
+ end
245
+ end
231
246
  end
232
247
 
233
248
  describe MSpecTag, "#run" do
@@ -354,4 +369,26 @@ describe MSpecTag, "#register" do
354
369
  @config[:formatter].should be_false
355
370
  end
356
371
  end
372
+
373
+ describe "when config[:tagger] is :purge" do
374
+ before :each do
375
+ @config[:tagger] = :purge
376
+ end
377
+
378
+ it "creates a TagPurgeAction" do
379
+ TagPurgeAction.should_receive(:new).and_return(@tl)
380
+ @tl.should_receive(:register)
381
+ @script.register
382
+ end
383
+
384
+ it "registers MSpec in pretend mode" do
385
+ MSpec.should_receive(:register_mode).with(:pretend)
386
+ @script.register
387
+ end
388
+
389
+ it "sets config[:formatter] to false" do
390
+ @script.register
391
+ @config[:formatter].should be_false
392
+ end
393
+ end
357
394
  end
@@ -0,0 +1,26 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/helpers/argv'
3
+
4
+ describe Object, "#argv" do
5
+ before :each do
6
+ ScratchPad.clear
7
+
8
+ @saved_argv = ARGV
9
+ @argv = ["a", "b"]
10
+ end
11
+
12
+ it "replaces and restores the value of ARGV" do
13
+ argv @argv
14
+ ARGV.should == @argv
15
+ argv :restore
16
+ ARGV.should == @saved_argv
17
+ end
18
+
19
+ it "yields to the block after setting ARGV" do
20
+ argv @argv do
21
+ ScratchPad.record ARGV
22
+ end
23
+ ScratchPad.recorded.should == @argv
24
+ ARGV.should == @saved_argv
25
+ end
26
+ end
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/helpers/fixture'
3
+
4
+ describe Object, "#fixture" do
5
+ before :each do
6
+ @dir = File.expand_path(Dir.pwd)
7
+ end
8
+
9
+ it "returns the expanded path to a fixture file" do
10
+ name = fixture("some/path/file.rb", "dir", "file.txt")
11
+ name.should == "#{@dir}/some/path/fixtures/dir/file.txt"
12
+ end
13
+
14
+ it "omits '/shared' if it the suffix of the directory string" do
15
+ name = fixture("some/path/shared/file.rb", "dir", "file.txt")
16
+ name.should == "#{@dir}/some/path/fixtures/dir/file.txt"
17
+ end
18
+ end
@@ -12,4 +12,8 @@ describe Object, "#flunk" do
12
12
  it "raises an ExpectationNotMetError unconditionally" do
13
13
  lambda { flunk }.should raise_error(ExpectationNotMetError)
14
14
  end
15
+
16
+ it "accepts on argument for an optional message" do
17
+ lambda {flunk "test"}.should raise_error(ExpectationNotMetError)
18
+ end
15
19
  end
@@ -1,5 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
- require 'mspec/helpers/ruby_exe'
2
+ require 'mspec/helpers/ruby_exe'
3
3
  require 'rbconfig'
4
4
 
5
5
  class RubyExeSpecs
@@ -61,15 +61,40 @@ end
61
61
 
62
62
  describe "#resolve_ruby_exe" do
63
63
  before :all do
64
+ @verbose = $VERBOSE
65
+ $VERBOSE = nil
66
+
67
+ @name = "ruby_spec_exe"
68
+ end
69
+
70
+ before :each do
71
+ @ruby_platform = Object.const_get :RUBY_PLATFORM
72
+
64
73
  @script = RubyExeSpecs.new
65
74
  end
66
75
 
76
+ after :each do
77
+ Object.const_set :RUBY_PLATFORM, @ruby_platform
78
+ end
79
+
80
+ after :all do
81
+ $VERBOSE = @verbose
82
+ end
83
+
67
84
  it "returns the value returned by #ruby_exe_options if it exists and is executable" do
68
- name = "ruby_spec_exe"
69
- @script.should_receive(:ruby_exe_options).and_return(name)
70
- File.should_receive(:exists?).with(name).and_return(true)
71
- File.should_receive(:executable?).with(name).and_return(true)
72
- @script.resolve_ruby_exe.should == name
85
+ Object.const_set :RUBY_PLATFORM, "notwindows"
86
+ @script.should_receive(:ruby_exe_options).and_return(@name)
87
+ File.should_receive(:exists?).with(@name).and_return(true)
88
+ File.should_receive(:executable?).with(@name).and_return(true)
89
+ @script.resolve_ruby_exe.should == @name
90
+ end
91
+
92
+ it "returns the value returned by #ruby_exe_options if it exists on Windows platforms" do
93
+ Object.const_set :RUBY_PLATFORM, "mswin"
94
+ @script.should_receive(:ruby_exe_options).and_return(@name)
95
+ File.should_receive(:exists?).with(@name).and_return(true)
96
+ File.should_not_receive(:executable?)
97
+ @script.resolve_ruby_exe.should == @name
73
98
  end
74
99
 
75
100
  it "returns nil if no exe is found" do
@@ -89,6 +114,9 @@ describe Object, "#ruby_exe" do
89
114
  @ruby_exe = Object.const_get :RUBY_EXE
90
115
  Object.const_set :RUBY_EXE, 'ruby_spec_exe'
91
116
 
117
+ @file = "some/ruby/file.rb"
118
+ @code = %(some "real" 'ruby' code)
119
+
92
120
  @script = RubyExeSpecs.new
93
121
  end
94
122
 
@@ -99,16 +127,34 @@ describe Object, "#ruby_exe" do
99
127
  end
100
128
 
101
129
  it "executes the argument if it is a file that exists" do
102
- code = "some/ruby/file.rb"
103
- File.should_receive(:exists?).with(code).and_return(true)
130
+ File.should_receive(:exists?).with(@file).and_return(true)
104
131
  @script.should_receive(:`).with("ruby_spec_exe -w -Q some/ruby/file.rb")
105
- @script.ruby_exe code
132
+ @script.ruby_exe @file
133
+ end
134
+
135
+ it "executes the file with options and arguments" do
136
+ File.should_receive(:exists?).with(@file).and_return(true)
137
+ @script.should_receive(:`).with(
138
+ "ruby_spec_exe -w -Q -w -Cdir some/ruby/file.rb < file.txt")
139
+ @script.ruby_exe @file, :options => "-w -Cdir", :args => "< file.txt"
106
140
  end
107
141
 
108
142
  it "executes the argument with -e" do
109
- code = %(some "real" 'ruby' code)
110
- File.should_receive(:exists?).with(code).and_return(false)
111
- @script.should_receive(:`).with(%(ruby_spec_exe -w -Q -e "some \\"real\\" 'ruby' code"))
112
- @script.ruby_exe code
143
+ File.should_receive(:exists?).with(@code).and_return(false)
144
+ @script.should_receive(:`).with(
145
+ %(ruby_spec_exe -w -Q -e "some \\"real\\" 'ruby' code"))
146
+ @script.ruby_exe @code
147
+ end
148
+
149
+ it "executes the code with options and arguments" do
150
+ File.should_receive(:exists?).with(@code).and_return(false)
151
+ @script.should_receive(:`).with(
152
+ %(ruby_spec_exe -w -Q -W0 -Cdir -e "some \\"real\\" 'ruby' code" < file.txt))
153
+ @script.ruby_exe @code, :options => "-W0 -Cdir", :args => "< file.txt"
154
+ end
155
+
156
+ it "executes with options and arguments but without code or file" do
157
+ @script.should_receive(:`).with("ruby_spec_exe -w -Q -c > file.txt")
158
+ @script.ruby_exe nil, :options => "-c", :args => "> file.txt"
113
159
  end
114
160
  end
@@ -54,7 +54,7 @@ describe TagListAction, "#start" do
54
54
  end
55
55
  end
56
56
 
57
- describe TagListAction, "#laod" do
57
+ describe TagListAction, "#load" do
58
58
  before :each do
59
59
  @t1 = SpecTag.new "fails:I fail"
60
60
  @t2 = SpecTag.new "unstable:I'm unstable"
@@ -0,0 +1,153 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'mspec/runner/actions/tagpurge'
3
+ require 'mspec/runner/mspec'
4
+ require 'mspec/runner/example'
5
+ require 'mspec/runner/tag'
6
+
7
+ describe TagPurgeAction, "#start" do
8
+ before :each do
9
+ @stdout = $stdout
10
+ $stdout = IOStub.new
11
+ end
12
+
13
+ after :each do
14
+ $stdout = @stdout
15
+ end
16
+
17
+ it "prints a banner" do
18
+ action = TagPurgeAction.new
19
+ action.start
20
+ $stdout.should == "\nRemoving tags not matching any specs\n\n"
21
+ end
22
+ end
23
+
24
+ describe TagPurgeAction, "#load" do
25
+ before :each do
26
+ @t1 = SpecTag.new "fails:I fail"
27
+ @t2 = SpecTag.new "unstable:I'm unstable"
28
+ end
29
+
30
+ it "creates a MatchFilter for all tags" do
31
+ MSpec.should_receive(:read_tags).and_return([@t1, @t2])
32
+ MatchFilter.should_receive(:new).with(nil, "I fail", "I'm unstable")
33
+ TagPurgeAction.new.load
34
+ end
35
+ end
36
+
37
+ describe TagPurgeAction, "#after" do
38
+ before :each do
39
+ @state = mock("ExampleState")
40
+ @state.stub!(:description).and_return("str")
41
+
42
+ @action = TagPurgeAction.new
43
+ end
44
+
45
+ it "does not save the description if the filter does not match" do
46
+ @action.should_receive(:===).with("str").and_return(false)
47
+ @action.after @state
48
+ @action.matching.should == []
49
+ end
50
+
51
+ it "saves the description if the filter matches" do
52
+ @action.should_receive(:===).with("str").and_return(true)
53
+ @action.after @state
54
+ @action.matching.should == ["str"]
55
+ end
56
+ end
57
+
58
+ describe TagPurgeAction, "#unload" do
59
+ before :each do
60
+ @stdout = $stdout
61
+ $stdout = IOStub.new
62
+
63
+ @t1 = SpecTag.new "fails:I fail"
64
+ @t2 = SpecTag.new "unstable:I'm unstable"
65
+ @t3 = SpecTag.new "fails:I'm unstable"
66
+
67
+ MSpec.stub!(:read_tags).and_return([@t1, @t2, @t3])
68
+ MSpec.stub!(:write_tags)
69
+
70
+ @state = mock("ExampleState")
71
+ @state.stub!(:description).and_return("I'm unstable")
72
+
73
+ @action = TagPurgeAction.new
74
+ @action.load
75
+ @action.after @state
76
+ end
77
+
78
+ after :each do
79
+ $stdout = @stdout
80
+ end
81
+
82
+ it "does not rewrite any tags if there were no tags for the specs" do
83
+ MSpec.should_receive(:read_tags).and_return([])
84
+ MSpec.should_not_receive(:write_tags)
85
+
86
+ @action.load
87
+ @action.after @state
88
+ @action.unload
89
+
90
+ $stdout.should == ""
91
+ end
92
+
93
+ it "rewrites tags that were matched" do
94
+ MSpec.should_receive(:write_tags).with([@t2, @t3])
95
+ @action.unload
96
+ end
97
+
98
+ it "prints tags that were not matched" do
99
+ @action.unload
100
+ $stdout.should == "I fail\n"
101
+ end
102
+ end
103
+
104
+ describe TagPurgeAction, "#unload" do
105
+ before :each do
106
+ @stdout = $stdout
107
+ $stdout = IOStub.new
108
+
109
+ MSpec.stub!(:read_tags).and_return([])
110
+
111
+ @state = mock("ExampleState")
112
+ @state.stub!(:description).and_return("I'm unstable")
113
+
114
+ @action = TagPurgeAction.new
115
+ @action.load
116
+ @action.after @state
117
+ end
118
+
119
+ after :each do
120
+ $stdout = @stdout
121
+ end
122
+
123
+ it "deletes the tag file if no tags were found" do
124
+ MSpec.should_not_receive(:write_tags)
125
+ MSpec.should_receive(:delete_tags)
126
+ @action.unload
127
+ $stdout.should == ""
128
+ end
129
+ end
130
+
131
+ describe TagPurgeAction, "#register" do
132
+ before :each do
133
+ MSpec.stub!(:register)
134
+ @action = TagPurgeAction.new
135
+ end
136
+
137
+ it "registers itself with MSpec for the :unload event" do
138
+ MSpec.should_receive(:register).with(:unload, @action)
139
+ @action.register
140
+ end
141
+ end
142
+
143
+ describe TagPurgeAction, "#unregister" do
144
+ before :each do
145
+ MSpec.stub!(:unregister)
146
+ @action = TagPurgeAction.new
147
+ end
148
+
149
+ it "unregisters itself with MSpec for the :unload event" do
150
+ MSpec.should_receive(:unregister).with(:unload, @action)
151
+ @action.unregister
152
+ end
153
+ end
@@ -376,6 +376,46 @@ describe MSpec, ".read_tags" do
376
376
  end
377
377
  end
378
378
 
379
+ describe MSpec, ".read_tags" do
380
+ before :each do
381
+ @tag = SpecTag.new "fails:Some#method"
382
+ File.open(tmp("tags.txt"), "w") do |f|
383
+ f.puts ""
384
+ f.puts @tag
385
+ f.puts ""
386
+ end
387
+ MSpec.stub!(:tags_file).and_return(tmp("tags.txt"))
388
+ end
389
+
390
+ it "does not return a tag object for empty lines" do
391
+ MSpec.read_tags(["fails"]).should == [@tag]
392
+ end
393
+ end
394
+
395
+ describe MSpec, ".write_tags" do
396
+ before :each do
397
+ FileUtils.cp File.dirname(__FILE__) + "/tags.txt", tmp("tags.txt")
398
+ MSpec.stub!(:tags_file).and_return(tmp("tags.txt"))
399
+ @tag1 = SpecTag.new "check(broken):Tag#rewrite works"
400
+ @tag2 = SpecTag.new "broken:Tag#write_tags fails"
401
+ end
402
+
403
+ after :all do
404
+ File.delete tmp("tags.txt") rescue nil
405
+ end
406
+
407
+ it "overwrites the tags in the tag file" do
408
+ IO.read(tmp("tags.txt")).should == %[fail(broken):Some#method? works
409
+ incomplete(20%):The#best method ever
410
+ benchmark(0.01825):The#fastest method today
411
+ ]
412
+ MSpec.write_tags [@tag1, @tag2]
413
+ IO.read(tmp("tags.txt")).should == %[check(broken):Tag#rewrite works
414
+ broken:Tag#write_tags fails
415
+ ]
416
+ end
417
+ end
418
+
379
419
  describe MSpec, ".write_tag" do
380
420
  before :each do
381
421
  FileUtils.stub!(:mkdir_p)
@@ -434,6 +474,19 @@ benchmark(0.01825):The#fastest method today
434
474
  end
435
475
  end
436
476
 
477
+ describe MSpec, ".delete_tags" do
478
+ before :each do
479
+ @tags = tmp("tags.txt")
480
+ FileUtils.cp File.dirname(__FILE__) + "/tags.txt", @tags
481
+ MSpec.stub!(:tags_file).and_return(@tags)
482
+ end
483
+
484
+ it "deletes the tag file" do
485
+ MSpec.delete_tags
486
+ File.exists?(@tags).should be_false
487
+ end
488
+ end
489
+
437
490
  describe MSpec, ".expectation" do
438
491
  it "sets the flag that an expectation has been reported" do
439
492
  MSpec.clear_expectations
@@ -310,6 +310,10 @@ end
310
310
  describe MSpecScript, "#entries" do
311
311
  before :each do
312
312
  @script = MSpecScript.new
313
+
314
+ File.stub!(:expand_path).and_return("name")
315
+ File.stub!(:file?).and_return(false)
316
+ File.stub!(:directory?).and_return(false)
313
317
  end
314
318
 
315
319
  it "returns the pattern in an array if it is a file" do
@@ -319,20 +323,41 @@ describe MSpecScript, "#entries" do
319
323
  end
320
324
 
321
325
  it "returns Dir['pattern/**/*_spec.rb'] if pattern is a directory" do
322
- File.should_receive(:expand_path).with("dir").and_return("dir")
323
- File.should_receive(:file?).with("dir").and_return(false)
324
- File.should_receive(:directory?).with("dir").and_return(true)
325
- Dir.should_receive(:[]).with("dir/**/*_spec.rb").and_return(["dir1", "dir2"])
326
- @script.entries("dir").should == ["dir1", "dir2"]
326
+ File.should_receive(:directory?).with("name").and_return(true)
327
+ Dir.should_receive(:[]).with("name/**/*_spec.rb").and_return(["dir1", "dir2"])
328
+ @script.entries("name").should == ["dir1", "dir2"]
327
329
  end
328
330
 
329
331
  it "returns Dir[pattern] if pattern is neither a file nor a directory" do
330
- File.should_receive(:expand_path).with("pattern").and_return("pattern")
331
- File.should_receive(:file?).with("pattern").and_return(false)
332
- File.should_receive(:directory?).with("pattern").and_return(false)
333
332
  Dir.should_receive(:[]).with("pattern").and_return(["file1", "file2"])
334
333
  @script.entries("pattern").should == ["file1", "file2"]
335
334
  end
335
+
336
+ describe "with config[:prefix] set" do
337
+ before :each do
338
+ prefix = "prefix/dir"
339
+ @script.config[:prefix] = prefix
340
+ @name = prefix + "/name"
341
+ end
342
+
343
+ it "returns the pattern in an array if it is a file" do
344
+ File.should_receive(:expand_path).with(@name).and_return(@name)
345
+ File.should_receive(:file?).with(@name).and_return(true)
346
+ @script.entries("name").should == [@name]
347
+ end
348
+
349
+ it "returns Dir['pattern/**/*_spec.rb'] if pattern is a directory" do
350
+ File.should_receive(:expand_path).with(@name).and_return(@name)
351
+ File.should_receive(:directory?).with(@name).and_return(true)
352
+ Dir.should_receive(:[]).with(@name + "/**/*_spec.rb").and_return(["dir1", "dir2"])
353
+ @script.entries("name").should == ["dir1", "dir2"]
354
+ end
355
+
356
+ it "returns Dir[pattern] if pattern is neither a file nor a directory" do
357
+ Dir.should_receive(:[]).with("pattern").and_return(["file1", "file2"])
358
+ @script.entries("pattern").should == ["file1", "file2"]
359
+ end
360
+ end
336
361
  end
337
362
 
338
363
  describe MSpecScript, "#files" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
4
+ version: 1.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Ford
@@ -49,11 +49,12 @@ files:
49
49
  - lib/mspec/guards/support.rb
50
50
  - lib/mspec/guards/version.rb
51
51
  - lib/mspec/guards.rb
52
+ - lib/mspec/helpers/argv.rb
52
53
  - lib/mspec/helpers/bignum.rb
53
54
  - lib/mspec/helpers/const_lookup.rb
55
+ - lib/mspec/helpers/fixture.rb
54
56
  - lib/mspec/helpers/flunk.rb
55
57
  - lib/mspec/helpers/io.rb
56
- - lib/mspec/helpers/metaclass.rb
57
58
  - lib/mspec/helpers/ruby_exe.rb
58
59
  - lib/mspec/helpers/scratch.rb
59
60
  - lib/mspec/helpers/tmp.rb
@@ -88,6 +89,7 @@ files:
88
89
  - lib/mspec/runner/actions/gdb.rb
89
90
  - lib/mspec/runner/actions/tag.rb
90
91
  - lib/mspec/runner/actions/taglist.rb
92
+ - lib/mspec/runner/actions/tagpurge.rb
91
93
  - lib/mspec/runner/actions/tally.rb
92
94
  - lib/mspec/runner/actions/timer.rb
93
95
  - lib/mspec/runner/actions.rb
@@ -147,11 +149,12 @@ files:
147
149
  - spec/guards/superuser_spec.rb
148
150
  - spec/guards/support_spec.rb
149
151
  - spec/guards/version_spec.rb
152
+ - spec/helpers/argv_spec.rb
150
153
  - spec/helpers/bignum_spec.rb
151
154
  - spec/helpers/const_lookup_spec.rb
155
+ - spec/helpers/fixture_spec.rb
152
156
  - spec/helpers/flunk_spec.rb
153
157
  - spec/helpers/io_spec.rb
154
- - spec/helpers/metaclass_spec.rb
155
158
  - spec/helpers/ruby_exe_spec.rb
156
159
  - spec/helpers/scratch_spec.rb
157
160
  - spec/helpers/tmp_spec.rb
@@ -181,6 +184,7 @@ files:
181
184
  - spec/runner/actions/gdb_spec.rb
182
185
  - spec/runner/actions/tag_spec.rb
183
186
  - spec/runner/actions/taglist_spec.rb
187
+ - spec/runner/actions/tagpurge_spec.rb
184
188
  - spec/runner/actions/tally_spec.rb
185
189
  - spec/runner/actions/timer_spec.rb
186
190
  - spec/runner/context_spec.rb
@@ -1,12 +0,0 @@
1
- # Provides a convenience method for accessing the metaclass
2
- # of any object without overriding the method if it already
3
- # exists in an implementation.
4
- unless respond_to? :metaclass
5
- class Object
6
- def metaclass
7
- class << self
8
- self
9
- end
10
- end
11
- end
12
- end
@@ -1,14 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
- require 'mspec/helpers/metaclass'
3
-
4
- describe Object, "#metaclass" do
5
- it "returns the singleton class for an object" do
6
- obj = Object.new
7
- def obj.metaclass_test; end
8
- meta = obj.metaclass
9
-
10
- meta.instance_methods(false).should include("metaclass_test")
11
- obj.should_not be_instance_of(meta)
12
- obj.should be_kind_of(meta)
13
- end
14
- end