mspec 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. data/LICENSE +22 -0
  2. data/README +101 -0
  3. data/Rakefile +44 -0
  4. data/bin/mkspec +7 -0
  5. data/bin/mspec +7 -0
  6. data/bin/mspec-ci +8 -0
  7. data/bin/mspec-run +8 -0
  8. data/bin/mspec-tag +8 -0
  9. data/lib/mspec.rb +6 -0
  10. data/lib/mspec/commands/mkspec.rb +147 -0
  11. data/lib/mspec/commands/mspec-ci.rb +71 -0
  12. data/lib/mspec/commands/mspec-run.rb +80 -0
  13. data/lib/mspec/commands/mspec-tag.rb +87 -0
  14. data/lib/mspec/commands/mspec.rb +143 -0
  15. data/lib/mspec/expectations.rb +2 -0
  16. data/lib/mspec/expectations/expectations.rb +12 -0
  17. data/lib/mspec/expectations/should.rb +23 -0
  18. data/lib/mspec/guards.rb +13 -0
  19. data/lib/mspec/guards/bug.rb +27 -0
  20. data/lib/mspec/guards/compliance.rb +18 -0
  21. data/lib/mspec/guards/conflict.rb +16 -0
  22. data/lib/mspec/guards/endian.rb +40 -0
  23. data/lib/mspec/guards/extensions.rb +12 -0
  24. data/lib/mspec/guards/guard.rb +120 -0
  25. data/lib/mspec/guards/noncompliance.rb +12 -0
  26. data/lib/mspec/guards/platform.rb +38 -0
  27. data/lib/mspec/guards/quarantine.rb +15 -0
  28. data/lib/mspec/guards/runner.rb +30 -0
  29. data/lib/mspec/guards/superuser.rb +15 -0
  30. data/lib/mspec/guards/support.rb +12 -0
  31. data/lib/mspec/guards/version.rb +40 -0
  32. data/lib/mspec/helpers.rb +6 -0
  33. data/lib/mspec/helpers/bignum.rb +5 -0
  34. data/lib/mspec/helpers/const_lookup.rb +5 -0
  35. data/lib/mspec/helpers/flunk.rb +5 -0
  36. data/lib/mspec/helpers/io.rb +13 -0
  37. data/lib/mspec/helpers/scratch.rb +17 -0
  38. data/lib/mspec/helpers/tmp.rb +32 -0
  39. data/lib/mspec/matchers.rb +16 -0
  40. data/lib/mspec/matchers/base.rb +95 -0
  41. data/lib/mspec/matchers/be_ancestor_of.rb +24 -0
  42. data/lib/mspec/matchers/be_close.rb +27 -0
  43. data/lib/mspec/matchers/be_empty.rb +20 -0
  44. data/lib/mspec/matchers/be_false.rb +20 -0
  45. data/lib/mspec/matchers/be_kind_of.rb +24 -0
  46. data/lib/mspec/matchers/be_nil.rb +20 -0
  47. data/lib/mspec/matchers/be_true.rb +20 -0
  48. data/lib/mspec/matchers/complain.rb +56 -0
  49. data/lib/mspec/matchers/eql.rb +26 -0
  50. data/lib/mspec/matchers/equal.rb +26 -0
  51. data/lib/mspec/matchers/equal_utf16.rb +34 -0
  52. data/lib/mspec/matchers/include.rb +32 -0
  53. data/lib/mspec/matchers/output.rb +67 -0
  54. data/lib/mspec/matchers/output_to_fd.rb +71 -0
  55. data/lib/mspec/matchers/raise_error.rb +48 -0
  56. data/lib/mspec/mocks.rb +3 -0
  57. data/lib/mspec/mocks/mock.rb +123 -0
  58. data/lib/mspec/mocks/object.rb +28 -0
  59. data/lib/mspec/mocks/proxy.rb +112 -0
  60. data/lib/mspec/runner.rb +13 -0
  61. data/lib/mspec/runner/actions.rb +6 -0
  62. data/lib/mspec/runner/actions/debug.rb +17 -0
  63. data/lib/mspec/runner/actions/filter.rb +40 -0
  64. data/lib/mspec/runner/actions/gdb.rb +17 -0
  65. data/lib/mspec/runner/actions/tag.rb +97 -0
  66. data/lib/mspec/runner/actions/tally.rb +80 -0
  67. data/lib/mspec/runner/actions/timer.rb +22 -0
  68. data/lib/mspec/runner/filters.rb +4 -0
  69. data/lib/mspec/runner/filters/match.rb +22 -0
  70. data/lib/mspec/runner/filters/profile.rb +54 -0
  71. data/lib/mspec/runner/filters/regexp.rb +7 -0
  72. data/lib/mspec/runner/filters/tag.rb +29 -0
  73. data/lib/mspec/runner/formatters.rb +7 -0
  74. data/lib/mspec/runner/formatters/dotted.rb +81 -0
  75. data/lib/mspec/runner/formatters/html.rb +87 -0
  76. data/lib/mspec/runner/formatters/specdoc.rb +27 -0
  77. data/lib/mspec/runner/formatters/spinner.rb +89 -0
  78. data/lib/mspec/runner/formatters/summary.rb +8 -0
  79. data/lib/mspec/runner/formatters/unit.rb +25 -0
  80. data/lib/mspec/runner/formatters/yaml.rb +43 -0
  81. data/lib/mspec/runner/mspec.rb +232 -0
  82. data/lib/mspec/runner/object.rb +20 -0
  83. data/lib/mspec/runner/shared.rb +12 -0
  84. data/lib/mspec/runner/state.rb +116 -0
  85. data/lib/mspec/runner/tag.rb +20 -0
  86. data/lib/mspec/utils/name_map.rb +130 -0
  87. data/lib/mspec/utils/options.rb +344 -0
  88. data/lib/mspec/utils/script.rb +77 -0
  89. data/lib/mspec/version.rb +3 -0
  90. data/spec/commands/mkspec_spec.rb +321 -0
  91. data/spec/commands/mspec_ci_spec.rb +139 -0
  92. data/spec/commands/mspec_run_spec.rb +146 -0
  93. data/spec/commands/mspec_spec.rb +359 -0
  94. data/spec/commands/mspec_tag_spec.rb +131 -0
  95. data/spec/expectations/expectations_spec.rb +16 -0
  96. data/spec/expectations/should_spec.rb +99 -0
  97. data/spec/guards/bug_spec.rb +137 -0
  98. data/spec/guards/compliance_spec.rb +70 -0
  99. data/spec/guards/conflict_spec.rb +20 -0
  100. data/spec/guards/endian_spec.rb +42 -0
  101. data/spec/guards/extensions_spec.rb +36 -0
  102. data/spec/guards/guard_spec.rb +355 -0
  103. data/spec/guards/noncompliance_spec.rb +36 -0
  104. data/spec/guards/platform_spec.rb +84 -0
  105. data/spec/guards/quarantine_spec.rb +19 -0
  106. data/spec/guards/runner_spec.rb +75 -0
  107. data/spec/guards/superuser_spec.rb +22 -0
  108. data/spec/guards/support_spec.rb +22 -0
  109. data/spec/guards/version_spec.rb +133 -0
  110. data/spec/helpers/bignum_spec.rb +11 -0
  111. data/spec/helpers/const_lookup_spec.rb +19 -0
  112. data/spec/helpers/flunk_spec.rb +15 -0
  113. data/spec/helpers/io_spec.rb +34 -0
  114. data/spec/helpers/scratch_spec.rb +22 -0
  115. data/spec/helpers/tmp_spec.rb +72 -0
  116. data/spec/matchers/base_spec.rb +180 -0
  117. data/spec/matchers/be_ancestor_of_spec.rb +28 -0
  118. data/spec/matchers/be_close_spec.rb +46 -0
  119. data/spec/matchers/be_empty_spec.rb +26 -0
  120. data/spec/matchers/be_false_spec.rb +28 -0
  121. data/spec/matchers/be_kind_of_spec.rb +29 -0
  122. data/spec/matchers/be_nil_spec.rb +27 -0
  123. data/spec/matchers/be_true_spec.rb +28 -0
  124. data/spec/matchers/complain_spec.rb +52 -0
  125. data/spec/matchers/eql_spec.rb +33 -0
  126. data/spec/matchers/equal_spec.rb +33 -0
  127. data/spec/matchers/equal_utf16_spec.rb +47 -0
  128. data/spec/matchers/include_spec.rb +37 -0
  129. data/spec/matchers/output_spec.rb +74 -0
  130. data/spec/matchers/output_to_fd_spec.rb +33 -0
  131. data/spec/matchers/raise_error_spec.rb +56 -0
  132. data/spec/mocks/mock_spec.rb +272 -0
  133. data/spec/mocks/proxy_spec.rb +259 -0
  134. data/spec/runner/actions/debug_spec.rb +61 -0
  135. data/spec/runner/actions/filter_spec.rb +84 -0
  136. data/spec/runner/actions/gdb_spec.rb +61 -0
  137. data/spec/runner/actions/tag_spec.rb +253 -0
  138. data/spec/runner/actions/tally_spec.rb +107 -0
  139. data/spec/runner/actions/timer_spec.rb +42 -0
  140. data/spec/runner/filters/a.yaml +4 -0
  141. data/spec/runner/filters/b.yaml +11 -0
  142. data/spec/runner/filters/match_spec.rb +44 -0
  143. data/spec/runner/filters/profile_spec.rb +117 -0
  144. data/spec/runner/filters/regexp_spec.rb +13 -0
  145. data/spec/runner/filters/tag_spec.rb +77 -0
  146. data/spec/runner/formatters/dotted_spec.rb +184 -0
  147. data/spec/runner/formatters/html_spec.rb +191 -0
  148. data/spec/runner/formatters/specdoc_spec.rb +57 -0
  149. data/spec/runner/formatters/spinner_spec.rb +78 -0
  150. data/spec/runner/formatters/summary_spec.rb +29 -0
  151. data/spec/runner/formatters/unit_spec.rb +71 -0
  152. data/spec/runner/formatters/yaml_spec.rb +123 -0
  153. data/spec/runner/mspec_spec.rb +393 -0
  154. data/spec/runner/shared_spec.rb +41 -0
  155. data/spec/runner/state_spec.rb +535 -0
  156. data/spec/runner/tag_spec.rb +93 -0
  157. data/spec/runner/tags.txt +3 -0
  158. data/spec/spec_helper.rb +46 -0
  159. data/spec/utils/name_map_spec.rb +178 -0
  160. data/spec/utils/options_spec.rb +862 -0
  161. data/spec/utils/script_spec.rb +240 -0
  162. metadata +217 -0
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+
5
+ require 'optparse'
6
+ require 'mspec/utils/options'
7
+ require 'mspec/utils/script'
8
+
9
+
10
+ class MSpecRun < MSpecScript
11
+ def options(argv=ARGV)
12
+ options = MSpecOptions.new config, "run", "", 28, " "
13
+
14
+ options.separator " Ask yourself:"
15
+ options.separator " 1. What specs to run?"
16
+ options.separator " 2. How to modify the execution?"
17
+ options.separator " 3. How to display the output?"
18
+ options.separator " 4. What action to perform?"
19
+ options.separator " 5. When to perform it?"
20
+
21
+ options.separator "\n What specs to run"
22
+ options.add_filters
23
+
24
+ options.separator "\n How to modify the execution"
25
+ options.add_config { |f| load f }
26
+ options.add_name
27
+ options.add_tags_dir
28
+ options.add_randomize
29
+ options.add_pretend
30
+ options.add_interrupt
31
+
32
+ options.separator "\n How to display their output"
33
+ options.add_formatters
34
+ options.add_verbose
35
+
36
+ options.separator "\n What action to perform"
37
+ options.add_actions
38
+ options.add_verify
39
+
40
+ options.separator "\n When to perform it"
41
+ options.add_action_filters
42
+
43
+ options.separator "\n Help!"
44
+ options.add_version
45
+ options.add_help
46
+
47
+ options.separator "\n How might this work in the real world?"
48
+ options.separator "\n 1. To simply run some specs"
49
+ options.separator "\n $ mspec path/to/the/specs"
50
+ options.separator " mspec path/to/the_file_spec.rb"
51
+ options.separator "\n 2. To run specs tagged with 'fails'"
52
+ options.separator "\n $ mspec -g fails path/to/the_file_spec.rb"
53
+ options.separator "\n 3. To start the debugger before the spec matching 'this crashes'"
54
+ options.separator "\n $ mspec --spec-debug -S 'this crashes' path/to/the_file_spec.rb"
55
+ options.separator ""
56
+
57
+ @patterns = options.parse argv
58
+ if @patterns.empty?
59
+ puts options.parser
60
+ puts "No files specified."
61
+ exit 1
62
+ end
63
+ end
64
+
65
+ def run
66
+ files = []
67
+ @patterns.each do |item|
68
+ stat = File.stat(File.expand_path(item))
69
+ files << item if stat.file?
70
+ files.concat(Dir[item+"/**/*_spec.rb"].sort) if stat.directory?
71
+ end
72
+
73
+ MSpec.register_tags_path config[:tags_dir]
74
+ MSpec.register_files files
75
+
76
+ MSpec.process
77
+ exit MSpec.exit_code
78
+ end
79
+ end
80
+
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'mspec/utils/options'
5
+ require 'mspec/utils/script'
6
+
7
+
8
+ class MSpecTag < MSpecScript
9
+ def initialize
10
+ super
11
+
12
+ config[:tagger] = :add
13
+ config[:tag] = 'fails:'
14
+ config[:outcome] = :fail
15
+ end
16
+
17
+ def options(argv=ARGV)
18
+ options = MSpecOptions.new config, "tag", "", 28, " "
19
+
20
+ options.separator " Ask yourself:"
21
+ options.separator " 1. What specs to run?"
22
+ options.separator " 2. How to modify the execution?"
23
+ options.separator " 3. How to display the output?"
24
+ options.separator " 4. What tag action to perform?"
25
+ options.separator " 5. When to perform it?"
26
+
27
+ options.separator "\n What specs to run"
28
+ options.add_filters
29
+
30
+ options.separator "\n How to modify the execution"
31
+ options.add_config { |f| load f }
32
+ options.add_name
33
+ options.add_tags_dir
34
+ options.add_pretend
35
+ options.add_interrupt
36
+
37
+ options.separator "\n How to display their output"
38
+ options.add_formatters
39
+ options.add_verbose
40
+
41
+ options.separator "\n What action to perform and when to perform it"
42
+ options.add_tagging
43
+
44
+ options.separator "\n Help!"
45
+ options.add_version
46
+ options.add_help
47
+
48
+ options.separator "\n How might this work in the real world?"
49
+ options.separator "\n 1. To add the 'fails' tag to failing specs"
50
+ options.separator "\n $ mspec tag path/to/the_file_spec.rb"
51
+ options.separator "\n 2. To remove the 'fails' tag from passing specs"
52
+ options.separator "\n $ mspec tag --del fails path/to/the_file_spec.rb"
53
+ options.separator ""
54
+
55
+ @patterns = options.parse argv
56
+ if @patterns.empty?
57
+ puts options.parser
58
+ puts "No files specified."
59
+ exit 1
60
+ end
61
+ end
62
+
63
+ def register
64
+ super
65
+
66
+ tag = SpecTag.new config[:tag]
67
+ tagger = TagAction.new(config[:tagger], config[:outcome], tag.tag, tag.comment,
68
+ config[:atags], config[:astrings])
69
+ tagger.register
70
+ end
71
+
72
+ def run
73
+ files = []
74
+ @patterns.each do |item|
75
+ stat = File.stat(File.expand_path(item))
76
+ files << item if stat.file?
77
+ files.concat(Dir[item+"/**/*_spec.rb"].sort) if stat.directory?
78
+ end
79
+
80
+ MSpec.register_tags_path config[:tags_dir]
81
+ MSpec.register_files files
82
+
83
+ MSpec.process
84
+ exit MSpec.exit_code
85
+ end
86
+ end
87
+
@@ -0,0 +1,143 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ MSPEC_HOME = File.expand_path(File.dirname(__FILE__) + '/../../..')
4
+
5
+ require 'optparse'
6
+ require 'mspec/utils/options'
7
+ require 'mspec/utils/script'
8
+ require 'mspec/helpers/tmp'
9
+ require 'mspec/runner/actions/timer'
10
+
11
+
12
+ class MSpecMain < MSpecScript
13
+ def initialize
14
+ config[:includes] = []
15
+ config[:requires] = []
16
+ config[:target] = ENV['RUBY'] || 'ruby'
17
+ config[:flags] = []
18
+ config[:command] = nil
19
+ config[:options] = []
20
+ end
21
+
22
+ def options(argv=ARGV)
23
+ if ["ci", "run", "tag"].include? argv[0]
24
+ config[:command] = argv.shift
25
+ config[:options] << "-h" if argv.delete("-h") || argv.delete("--help")
26
+ config[:options] << "-v" if argv.delete("-v") || argv.delete("--version")
27
+ end
28
+
29
+ options = MSpecOptions.new config, "[COMMAND]", "", 28, " "
30
+
31
+ options.separator ""
32
+ options.separator " The mspec command sets up and invokes the sub-commands"
33
+ options.separator " (see below) to enable, for instance, running the specs"
34
+ options.separator " with different implementations like ruby, jruby, rbx, etc.\n"
35
+
36
+ options.add_config do |f|
37
+ config[:options] << '-B' << f
38
+ end
39
+
40
+ options.add_targets
41
+
42
+ options.on("-D", "--gdb", "Run under gdb") do
43
+ config[:flags] << '--gdb'
44
+ end
45
+ options.on("-A", "--valgrind", "Run under valgrind") do
46
+ config[:flags] << '--valgrind'
47
+ end
48
+ options.on("--warnings", "Don't supress warnings") do
49
+ config[:flags] << '-w'
50
+ ENV['OUTPUT_WARNINGS'] = '1'
51
+ end
52
+ options.on("-j", "--multi", "Run multiple (possibly parallel) subprocesses") do
53
+ config[:multi] = true
54
+ config[:options] << "-fy"
55
+ end
56
+ options.add_version
57
+ options.on("-h", "--help", "Show this message") do
58
+ puts options.parser
59
+ exit
60
+ end
61
+
62
+ # The rest of the help output
63
+ options.separator "\n where COMMAND is one of:\n"
64
+ options.separator " run - Run the specified specs (default)"
65
+ options.separator " ci - Run the known good specs"
66
+ options.separator " tag - Add or remove tags\n"
67
+ options.separator " mspec COMMAND -h for more options\n"
68
+
69
+ config[:options] += options.parser.filter! argv
70
+ options.parse argv
71
+ end
72
+
73
+ def register; end
74
+
75
+ def parallel
76
+ @parallel ||= !(Object.const_defined?(:JRUBY_VERSION) ||
77
+ /(mswin|mingw)/ =~ RUBY_PLATFORM)
78
+ end
79
+
80
+ def fork(&block)
81
+ parallel ? Kernel.fork(&block) : block.call
82
+ end
83
+
84
+ def report(files, timer)
85
+ require 'yaml'
86
+
87
+ exceptions = []
88
+ tally = Tally.new
89
+
90
+ files.each do |file|
91
+ d = File.open(file, "r") { |f| YAML.load f }
92
+ File.delete file
93
+
94
+ exceptions += Array(d['exceptions'])
95
+ tally.files! d['files']
96
+ tally.examples! d['examples']
97
+ tally.expectations! d['expectations']
98
+ tally.errors! d['errors']
99
+ tally.failures! d['failures']
100
+ end
101
+
102
+ print "\n"
103
+ exceptions.each_with_index do |exc, index|
104
+ print "\n#{index+1})\n", exc, "\n"
105
+ end
106
+ print "\n#{timer.format}\n\n#{tally.format}\n"
107
+ end
108
+
109
+ def multi_exec(argv)
110
+ timer = TimerAction.new
111
+ timer.start
112
+
113
+ files = config[:ci_files].inject([]) do |list, item|
114
+ name = tmp "mspec-ci-multi-#{list.size}"
115
+
116
+ rest = argv + ["-o", name, item]
117
+ fork { system [config[:target], *rest].join(" ") }
118
+
119
+ list << name
120
+ end
121
+
122
+ Process.waitall
123
+ timer.finish
124
+ report files, timer
125
+ end
126
+
127
+ def run
128
+ ENV['MSPEC_RUNNER'] = '1'
129
+
130
+ argv = config[:flags]
131
+ argv.concat config[:includes]
132
+ argv.concat config[:requires]
133
+ argv << "#{MSPEC_HOME}/bin/mspec-#{ config[:command] || "run" }"
134
+ argv.concat config[:options]
135
+
136
+ if config[:multi] and config[:command] == "ci"
137
+ multi_exec argv
138
+ else
139
+ exec config[:target], *argv
140
+ end
141
+ end
142
+ end
143
+
@@ -0,0 +1,2 @@
1
+ require 'mspec/expectations/expectations'
2
+ require 'mspec/expectations/should'
@@ -0,0 +1,12 @@
1
+ class ExpectationNotMetError < StandardError; end
2
+
3
+ class Expectation
4
+ def self.fail_with(expected, actual)
5
+ if expected.to_s.size + actual.to_s.size > 80
6
+ message = expected.to_s.chomp + "\n" + actual.to_s
7
+ else
8
+ message = expected.to_s + " " + actual.to_s
9
+ end
10
+ Kernel.raise ExpectationNotMetError, message
11
+ end
12
+ end
@@ -0,0 +1,23 @@
1
+ class Object
2
+ def should(matcher=nil)
3
+ MSpec.actions :expectation, MSpec.current.state
4
+ if matcher
5
+ unless matcher.matches?(self)
6
+ Expectation.fail_with(*matcher.failure_message)
7
+ end
8
+ else
9
+ PositiveOperatorMatcher.new(self)
10
+ end
11
+ end
12
+
13
+ def should_not(matcher=nil)
14
+ MSpec.actions :expectation, MSpec.current.state
15
+ if matcher
16
+ if matcher.matches?(self)
17
+ Expectation.fail_with(*matcher.negative_failure_message)
18
+ end
19
+ else
20
+ NegativeOperatorMatcher.new(self)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ require 'mspec/guards/bug'
2
+ require 'mspec/guards/compliance'
3
+ require 'mspec/guards/extensions'
4
+ require 'mspec/guards/guard'
5
+ require 'mspec/guards/noncompliance'
6
+ require 'mspec/guards/platform'
7
+ require 'mspec/guards/quarantine'
8
+ require 'mspec/guards/runner'
9
+ require 'mspec/guards/support'
10
+ require 'mspec/guards/endian'
11
+ require 'mspec/guards/superuser'
12
+ require 'mspec/guards/conflict'
13
+ require 'mspec/guards/version'
@@ -0,0 +1,27 @@
1
+ require 'mspec/guards/version'
2
+
3
+ class BugGuard < VersionGuard
4
+ def initialize(bug, version)
5
+ @bug = bug
6
+ @version = to_v version
7
+ end
8
+
9
+ def to_v(str)
10
+ major, minor, tiny, patch = str.split "."
11
+ tiny = 99 unless tiny
12
+ patch = 9999 unless patch
13
+ ("1%02d%02d%02d%04d" % [major, minor, tiny, patch].map { |x| x.to_i }).to_i
14
+ end
15
+
16
+ def match?
17
+ implementation?(:ruby, :ruby18, :ruby19) && ruby_version <= @version
18
+ end
19
+ end
20
+
21
+ class Object
22
+ def ruby_bug(bug="Please add a bug tracker number", version="0")
23
+ g = BugGuard.new bug, version
24
+ yield if g.yield? true
25
+ g.unregister
26
+ end
27
+ end
@@ -0,0 +1,18 @@
1
+ require 'mspec/guards/guard'
2
+
3
+ class ComplianceGuard < SpecGuard
4
+ end
5
+
6
+ class Object
7
+ def compliant_on(*args)
8
+ g = ComplianceGuard.new(*args)
9
+ yield if g.yield?
10
+ g.unregister
11
+ end
12
+
13
+ def not_compliant_on(*args)
14
+ g = ComplianceGuard.new(*args)
15
+ yield if g.yield? true
16
+ g.unregister
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ require 'mspec/guards/guard'
2
+
3
+ class ConflictsGuard < SpecGuard
4
+ def match?
5
+ constants = Object.constants
6
+ @args.any? { |mod| constants.include? mod.to_s }
7
+ end
8
+ end
9
+
10
+ class Object
11
+ def conflicts_with(*modules)
12
+ g = ConflictsGuard.new(*modules)
13
+ yield if g.yield? true
14
+ g.unregister
15
+ end
16
+ end
@@ -0,0 +1,40 @@
1
+ require 'mspec/guards/guard'
2
+
3
+ # Despite that these are inverses, the two classes are
4
+ # used to simplify MSpec guard reporting modes
5
+
6
+ class BigEndianGuard < SpecGuard
7
+ def pattern
8
+ [1].pack('L')
9
+ end
10
+ private :pattern
11
+
12
+ def match?
13
+ pattern[-1] == 1
14
+ end
15
+ end
16
+
17
+ class LittleEndianGuard < SpecGuard
18
+ def pattern
19
+ [1].pack('L')
20
+ end
21
+ private :pattern
22
+
23
+ def match?
24
+ pattern[-1] == 0
25
+ end
26
+ end
27
+
28
+ class Object
29
+ def big_endian
30
+ g = BigEndianGuard.new
31
+ yield if g.yield?
32
+ g.unregister
33
+ end
34
+
35
+ def little_endian
36
+ g = LittleEndianGuard.new
37
+ yield if g.yield?
38
+ g.unregister
39
+ end
40
+ end