mspec 1.5.9 → 1.5.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/Rakefile +1 -1
  2. data/lib/mspec/commands/mspec-ci.rb +5 -1
  3. data/lib/mspec/commands/mspec-run.rb +8 -5
  4. data/lib/mspec/guards/background.rb +2 -0
  5. data/lib/mspec/guards/bug.rb +5 -1
  6. data/lib/mspec/guards/compliance.rb +10 -0
  7. data/lib/mspec/guards/conflict.rb +2 -0
  8. data/lib/mspec/guards/endian.rb +4 -0
  9. data/lib/mspec/guards/extensions.rb +2 -0
  10. data/lib/mspec/guards/guard.rb +49 -25
  11. data/lib/mspec/guards/noncompliance.rb +2 -0
  12. data/lib/mspec/guards/platform.rb +5 -0
  13. data/lib/mspec/guards/quarantine.rb +2 -0
  14. data/lib/mspec/guards/runner.rb +4 -0
  15. data/lib/mspec/guards/superuser.rb +2 -0
  16. data/lib/mspec/guards/support.rb +2 -0
  17. data/lib/mspec/guards/tty.rb +2 -0
  18. data/lib/mspec/guards/version.rb +3 -0
  19. data/lib/mspec/matchers.rb +1 -0
  20. data/lib/mspec/matchers/have_constant.rb +30 -0
  21. data/lib/mspec/matchers/method.rb +4 -3
  22. data/lib/mspec/matchers/stringsymboladapter.rb +8 -0
  23. data/lib/mspec/runner/actions/tally.rb +13 -3
  24. data/lib/mspec/runner/context.rb +8 -1
  25. data/lib/mspec/runner/mspec.rb +16 -0
  26. data/lib/mspec/utils/options.rb +10 -3
  27. data/lib/mspec/version.rb +1 -1
  28. data/spec/guards/background_spec.rb +15 -0
  29. data/spec/guards/bug_spec.rb +28 -10
  30. data/spec/guards/compliance_spec.rb +54 -0
  31. data/spec/guards/conflict_spec.rb +19 -0
  32. data/spec/guards/endian_spec.rb +26 -0
  33. data/spec/guards/extensions_spec.rb +20 -0
  34. data/spec/guards/guard_spec.rb +69 -52
  35. data/spec/guards/noncompliance_spec.rb +20 -0
  36. data/spec/guards/platform_spec.rb +26 -0
  37. data/spec/guards/quarantine_spec.rb +16 -0
  38. data/spec/guards/runner_spec.rb +26 -0
  39. data/spec/guards/superuser_spec.rb +13 -0
  40. data/spec/guards/support_spec.rb +20 -0
  41. data/spec/guards/tty_spec.rb +16 -0
  42. data/spec/guards/version_spec.rb +13 -0
  43. data/spec/matchers/have_constant_spec.rb +37 -0
  44. data/spec/matchers/stringsymboladapter_spec.rb +40 -0
  45. data/spec/runner/actions/tagpurge_spec.rb +1 -0
  46. data/spec/runner/actions/tally_spec.rb +64 -0
  47. data/spec/runner/context_spec.rb +24 -11
  48. data/spec/runner/formatters/html_spec.rb +1 -0
  49. data/spec/runner/mspec_spec.rb +31 -0
  50. data/spec/utils/options_spec.rb +59 -0
  51. metadata +6 -3
  52. data/spec/matchers/method_spec.rb +0 -36
data/Rakefile CHANGED
@@ -18,7 +18,7 @@ spec = Gem::Specification.new do |s|
18
18
 
19
19
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
20
20
  s.authors = ["Brian Ford"]
21
- s.date = %q{2009-2-10}
21
+ s.date = %q{2009-3-1}
22
22
  s.email = %q{bford@engineyard.com}
23
23
  s.has_rdoc = true
24
24
  s.extra_rdoc_files = %w[ README LICENSE ]
@@ -13,6 +13,7 @@ class MSpecCI < MSpecScript
13
13
 
14
14
  options.doc " Ask yourself:"
15
15
  options.doc " 1. How to run the specs?"
16
+ options.doc " 2. How to modify the guard behavior?"
16
17
  options.doc " 2. How to display the output?"
17
18
  options.doc " 3. What action to perform?"
18
19
  options.doc " 4. When to perform it?"
@@ -24,9 +25,12 @@ class MSpecCI < MSpecScript
24
25
  options.name
25
26
  options.pretend
26
27
  options.background
27
- options.unguarded
28
28
  options.interrupt
29
29
 
30
+ options.doc "\n How to modify the guard behavior"
31
+ options.unguarded
32
+ options.verify
33
+
30
34
  options.doc "\n How to display their output"
31
35
  options.formatters
32
36
  options.verbose
@@ -20,9 +20,10 @@ class MSpecRun < MSpecScript
20
20
  options.doc " Ask yourself:"
21
21
  options.doc " 1. What specs to run?"
22
22
  options.doc " 2. How to modify the execution?"
23
- options.doc " 3. How to display the output?"
24
- options.doc " 4. What action to perform?"
25
- options.doc " 5. When to perform it?"
23
+ options.doc " 3. How to modify the guard behavior?"
24
+ options.doc " 4. How to display the output?"
25
+ options.doc " 5. What action to perform?"
26
+ options.doc " 6. When to perform it?"
26
27
 
27
28
  options.doc "\n What specs to run"
28
29
  options.filters
@@ -35,16 +36,18 @@ class MSpecRun < MSpecScript
35
36
  options.randomize
36
37
  options.pretend
37
38
  options.background
38
- options.unguarded
39
39
  options.interrupt
40
40
 
41
+ options.doc "\n How to modify the guard behavior"
42
+ options.unguarded
43
+ options.verify
44
+
41
45
  options.doc "\n How to display their output"
42
46
  options.formatters
43
47
  options.verbose
44
48
 
45
49
  options.doc "\n What action to perform"
46
50
  options.actions
47
- options.verify
48
51
 
49
52
  options.doc "\n When to perform it"
50
53
  options.action_filters
@@ -13,7 +13,9 @@ end
13
13
  class Object
14
14
  def process_is_foreground
15
15
  g = BackgroundGuard.new
16
+ g.name = :process_is_foreground
16
17
  yield if g.yield? true
18
+ ensure
17
19
  g.unregister
18
20
  end
19
21
  end
@@ -4,17 +4,21 @@ class BugGuard < VersionGuard
4
4
  def initialize(bug, version)
5
5
  @bug = bug
6
6
  @version = SpecVersion.new version, true
7
+ self.parameters = [@bug, @version]
7
8
  end
8
9
 
9
10
  def match?
11
+ return false if MSpec.mode? :no_ruby_bug
10
12
  standard? && ruby_version <= @version
11
13
  end
12
14
  end
13
15
 
14
16
  class Object
15
- def ruby_bug(bug="Please add a bug tracker number", version="0")
17
+ def ruby_bug(bug, version)
16
18
  g = BugGuard.new bug, version
19
+ g.name = :ruby_bug
17
20
  yield if g.yield? true
21
+ ensure
18
22
  g.unregister
19
23
  end
20
24
  end
@@ -2,12 +2,18 @@ require 'mspec/guards/guard'
2
2
 
3
3
  class CompliantOnGuard < SpecGuard
4
4
  def match?
5
+ if @args.include? :ruby
6
+ raise Exception, "improper use of compliant_on guard"
7
+ end
5
8
  standard? or implementation?(*@args)
6
9
  end
7
10
  end
8
11
 
9
12
  class NotCompliantOnGuard < SpecGuard
10
13
  def match?
14
+ if @args.include? :ruby
15
+ raise Exception, "improper use of not_compliant_on guard"
16
+ end
11
17
  standard? or !implementation?(*@args)
12
18
  end
13
19
  end
@@ -15,13 +21,17 @@ end
15
21
  class Object
16
22
  def compliant_on(*args)
17
23
  g = CompliantOnGuard.new(*args)
24
+ g.name = :compliant_on
18
25
  yield if g.yield?
26
+ ensure
19
27
  g.unregister
20
28
  end
21
29
 
22
30
  def not_compliant_on(*args)
23
31
  g = NotCompliantOnGuard.new(*args)
32
+ g.name = :not_compliant_on
24
33
  yield if g.yield?
34
+ ensure
25
35
  g.unregister
26
36
  end
27
37
  end
@@ -10,7 +10,9 @@ end
10
10
  class Object
11
11
  def conflicts_with(*modules)
12
12
  g = ConflictsGuard.new(*modules)
13
+ g.name = :conflicts_with
13
14
  yield if g.yield? true
15
+ ensure
14
16
  g.unregister
15
17
  end
16
18
  end
@@ -28,13 +28,17 @@ end
28
28
  class Object
29
29
  def big_endian
30
30
  g = BigEndianGuard.new
31
+ g.name = :big_endian
31
32
  yield if g.yield?
33
+ ensure
32
34
  g.unregister
33
35
  end
34
36
 
35
37
  def little_endian
36
38
  g = LittleEndianGuard.new
39
+ g.name = :little_endian
37
40
  yield if g.yield?
41
+ ensure
38
42
  g.unregister
39
43
  end
40
44
  end
@@ -12,7 +12,9 @@ end
12
12
  class Object
13
13
  def extended_on(*args)
14
14
  g = ExtensionsGuard.new(*args)
15
+ g.name = :extended_on
15
16
  yield if g.yield?
17
+ ensure
16
18
  g.unregister
17
19
  end
18
20
  end
@@ -2,21 +2,32 @@ require 'mspec/runner/mspec'
2
2
  require 'mspec/runner/actions/tally'
3
3
 
4
4
  class SpecGuard
5
- def self.register
6
- unless @registered
7
- @tally = TallyAction.new
8
- @tally.register
9
- MSpec.register :finish, self
10
- @registered = true
11
- end
5
+ def self.report
6
+ @report ||= Hash.new { |h,k| h[k] = [] }
12
7
  end
13
8
 
14
- def self.unregister
15
- @tally.unregister if @tally
9
+ def self.clear
10
+ @report = nil
16
11
  end
17
12
 
18
13
  def self.finish
19
- print "\n#{self.class}\n#{@tally.format}\n"
14
+ report.keys.sort.each do |key|
15
+ desc = report[key]
16
+ size = desc.size
17
+ spec = size == 1 ? "spec" : "specs"
18
+ print "\n\n#{size} #{spec} omitted by guard: #{key}:\n"
19
+ desc.each { |desc| print "\n", desc }
20
+ end
21
+
22
+ print "\n\n"
23
+ end
24
+
25
+ def self.guards
26
+ @guards ||= []
27
+ end
28
+
29
+ def self.clear_guards
30
+ @guards = []
20
31
  end
21
32
 
22
33
  # Returns a partial Ruby version string based on +which+. For example,
@@ -49,41 +60,54 @@ class SpecGuard
49
60
  !!key.match(/(mswin|mingw)/)
50
61
  end
51
62
 
63
+ attr_accessor :name, :parameters
52
64
 
53
65
  def initialize(*args)
54
- @args = args
66
+ self.parameters = @args = args
55
67
  end
56
68
 
57
69
  def yield?(invert=false)
58
- if MSpec.mode? :unguarded
59
- return true
60
- elsif MSpec.mode? :report
61
- self.class.register
62
- MSpec.register :before, self
70
+ return true if MSpec.mode? :unguarded
71
+
72
+ allow = match? ^ invert
73
+
74
+ if not allow and reporting?
75
+ MSpec.guard
76
+ MSpec.register :finish, SpecGuard
77
+ MSpec.register :add, self
63
78
  return true
64
79
  elsif MSpec.mode? :verify
65
- self.class.register
66
- MSpec.register :after, self
67
80
  return true
68
81
  end
69
- return match? ^ invert
82
+
83
+ allow
70
84
  end
71
85
 
72
86
  def ===(other)
73
87
  true
74
88
  end
75
89
 
76
- def before(state)
90
+ def reporting?
91
+ MSpec.mode?(:report) or
92
+ (MSpec.mode?(:report_on) and SpecGuard.guards.include?(name))
93
+ end
94
+
95
+ def report_key
96
+ "#{name} #{parameters.join(", ")}"
97
+ end
98
+
99
+ def record(description)
100
+ SpecGuard.report[report_key] << description
77
101
  end
78
102
 
79
- def after(state)
103
+ def add(example)
104
+ record example.description
105
+ MSpec.retrieve(:formatter).tally.counter.guards!
80
106
  end
81
107
 
82
108
  def unregister
83
- MSpec.unregister :before, self
84
- MSpec.unregister :after, self
85
- MSpec.unregister :exclude, self
86
- self.class.unregister
109
+ MSpec.unguard
110
+ MSpec.unregister :add, self
87
111
  end
88
112
 
89
113
  def implementation?(*args)
@@ -12,7 +12,9 @@ end
12
12
  class Object
13
13
  def deviates_on(*args)
14
14
  g = NonComplianceGuard.new(*args)
15
+ g.name = :deviates_on
15
16
  yield if g.yield?
17
+ ensure
16
18
  g.unregister
17
19
  end
18
20
  end
@@ -7,6 +7,7 @@ class PlatformGuard < SpecGuard
7
7
  else
8
8
  @options, @platforms = {}, args
9
9
  end
10
+ self.parameters = args
10
11
  end
11
12
 
12
13
  def match?
@@ -26,13 +27,17 @@ end
26
27
  class Object
27
28
  def platform_is(*args)
28
29
  g = PlatformGuard.new(*args)
30
+ g.name = :platform_is
29
31
  yield if g.yield?
32
+ ensure
30
33
  g.unregister
31
34
  end
32
35
 
33
36
  def platform_is_not(*args)
34
37
  g = PlatformGuard.new(*args)
38
+ g.name = :platform_is_not
35
39
  yield if g.yield? true
40
+ ensure
36
41
  g.unregister
37
42
  end
38
43
  end
@@ -9,7 +9,9 @@ end
9
9
  class Object
10
10
  def quarantine!
11
11
  g = QuarantineGuard.new
12
+ g.name = :quarantine!
12
13
  yield if g.yield?
14
+ ensure
13
15
  g.unregister
14
16
  end
15
17
  end
@@ -18,13 +18,17 @@ end
18
18
  class Object
19
19
  def runner_is(*args)
20
20
  g = RunnerGuard.new(*args)
21
+ g.name = :runner_is
21
22
  yield if g.yield?
23
+ ensure
22
24
  g.unregister
23
25
  end
24
26
 
25
27
  def runner_is_not(*args)
26
28
  g = RunnerGuard.new(*args)
29
+ g.name = :runner_is_not
27
30
  yield if g.yield? true
31
+ ensure
28
32
  g.unregister
29
33
  end
30
34
  end
@@ -9,7 +9,9 @@ end
9
9
  class Object
10
10
  def as_superuser
11
11
  g = SuperUserGuard.new
12
+ g.name = :as_superuser
12
13
  yield if g.yield?
14
+ ensure
13
15
  g.unregister
14
16
  end
15
17
  end
@@ -12,7 +12,9 @@ end
12
12
  class Object
13
13
  def not_supported_on(*args)
14
14
  g = SupportedGuard.new(*args)
15
+ g.name = :not_supported_on
15
16
  yield if g.yield?
17
+ ensure
16
18
  g.unregister
17
19
  end
18
20
  end
@@ -12,7 +12,9 @@ end
12
12
  class Object
13
13
  def with_tty
14
14
  g = TTYGuard.new
15
+ g.name = :with_tty
15
16
  yield if g.yield?
17
+ ensure
16
18
  g.unregister
17
19
  end
18
20
  end
@@ -11,6 +11,7 @@ class VersionGuard < SpecGuard
11
11
  b = SpecVersion.new version.last
12
12
  @version = version.exclude_end? ? a...b : a..b
13
13
  end
14
+ self.parameters = [version]
14
15
  end
15
16
 
16
17
  def ruby_version
@@ -29,7 +30,9 @@ end
29
30
  class Object
30
31
  def ruby_version_is(*args)
31
32
  g = VersionGuard.new(*args)
33
+ g.name = :ruby_version_is
32
34
  yield if g.yield?
35
+ ensure
33
36
  g.unregister
34
37
  end
35
38
  end
@@ -11,6 +11,7 @@ require 'mspec/matchers/eql'
11
11
  require 'mspec/matchers/equal'
12
12
  require 'mspec/matchers/equal_element'
13
13
  require 'mspec/matchers/equal_utf16'
14
+ require 'mspec/matchers/have_constant'
14
15
  require 'mspec/matchers/have_instance_method'
15
16
  require 'mspec/matchers/have_method'
16
17
  require 'mspec/matchers/have_private_instance_method'
@@ -0,0 +1,30 @@
1
+ require 'mspec/matchers/stringsymboladapter'
2
+
3
+ class HaveConstantMatcher
4
+ include StringSymbolAdapter
5
+
6
+ def initialize(name)
7
+ @name = convert_name name
8
+ end
9
+
10
+ def matches?(mod)
11
+ @mod = mod
12
+ @mod.constants.include? @name
13
+ end
14
+
15
+ def failure_message
16
+ ["Expected #{@mod} to have constant '#{@name.to_s}'",
17
+ "but it does not"]
18
+ end
19
+
20
+ def negative_failure_message
21
+ ["Expected #{@mod} NOT to have constant '#{@name.to_s}'",
22
+ "but it does"]
23
+ end
24
+ end
25
+
26
+ class Object
27
+ def have_constant(name)
28
+ HaveConstantMatcher.new name
29
+ end
30
+ end