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,29 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/expectations/expectations'
3
+ require 'mspec/matchers/be_kind_of'
4
+
5
+ describe BeKindOfMatcher do
6
+ it "matches when actual is a kind_of? expected" do
7
+ BeKindOfMatcher.new(Integer).matches?(1).should == true
8
+ BeKindOfMatcher.new(Fixnum).matches?(2).should == true
9
+ BeKindOfMatcher.new(Regexp).matches?(/m/).should == true
10
+ end
11
+
12
+ it "does not match when actual is not a kind_of? expected" do
13
+ BeKindOfMatcher.new(Integer).matches?(1.5).should == false
14
+ BeKindOfMatcher.new(String).matches?(:a).should == false
15
+ BeKindOfMatcher.new(Hash).matches?([]).should == false
16
+ end
17
+
18
+ it "provides a useful failure message" do
19
+ matcher = BeKindOfMatcher.new(Numeric)
20
+ matcher.matches?('string')
21
+ matcher.failure_message.should == ["Expected \"string\" (String)", "to be kind of Numeric"]
22
+ end
23
+
24
+ it "provides a useful negative failure message" do
25
+ matcher = BeKindOfMatcher.new(Numeric)
26
+ matcher.matches?(4.2)
27
+ matcher.negative_failure_message.should == ["Expected 4.2 (Float)", "not to be kind of Numeric"]
28
+ end
29
+ end
@@ -0,0 +1,27 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/expectations/expectations'
3
+ require 'mspec/matchers/be_nil'
4
+
5
+ describe BeNilMatcher do
6
+ it "matches when actual is nil" do
7
+ BeNilMatcher.new.matches?(nil).should == true
8
+ end
9
+
10
+ it "does not match when actual is not nil" do
11
+ BeNilMatcher.new.matches?("").should == false
12
+ BeNilMatcher.new.matches?(false).should == false
13
+ BeNilMatcher.new.matches?(0).should == false
14
+ end
15
+
16
+ it "provides a useful failure message" do
17
+ matcher = BeNilMatcher.new
18
+ matcher.matches?("some string")
19
+ matcher.failure_message.should == ["Expected \"some string\"", "to be nil"]
20
+ end
21
+
22
+ it "provides a useful negative failure message" do
23
+ matcher = BeNilMatcher.new
24
+ matcher.matches?(nil)
25
+ matcher.negative_failure_message.should == ["Expected nil", "not to be nil"]
26
+ end
27
+ end
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/expectations/expectations'
3
+ require 'mspec/matchers/be_true'
4
+
5
+ describe BeTrueMatcher do
6
+ it "matches when actual is true" do
7
+ BeTrueMatcher.new.matches?(true).should == true
8
+ end
9
+
10
+ it "does not match when actual is not true" do
11
+ BeTrueMatcher.new.matches?("").should == false
12
+ BeTrueMatcher.new.matches?(false).should == false
13
+ BeTrueMatcher.new.matches?(nil).should == false
14
+ BeTrueMatcher.new.matches?(0).should == false
15
+ end
16
+
17
+ it "provides a useful failure message" do
18
+ matcher = BeTrueMatcher.new
19
+ matcher.matches?("some string")
20
+ matcher.failure_message.should == ["Expected \"some string\"", "to be true"]
21
+ end
22
+
23
+ it "provides a useful negative failure message" do
24
+ matcher = BeTrueMatcher.new
25
+ matcher.matches?(true)
26
+ matcher.negative_failure_message.should == ["Expected true", "not to be true"]
27
+ end
28
+ end
@@ -0,0 +1,52 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/expectations/expectations'
3
+ require 'mspec/matchers/complain'
4
+
5
+ describe ComplainMatcher do
6
+ it "matches when executing the proc results in output to $stderr" do
7
+ proc = lambda { warn "I'm gonna tell yo mama" }
8
+ ComplainMatcher.new(nil).matches?(proc).should == true
9
+ end
10
+
11
+ it "maches when executing the proc results in the expected output to $stderr" do
12
+ proc = lambda { warn "Que haces?" }
13
+ ComplainMatcher.new("Que haces?\n").matches?(proc).should == true
14
+ ComplainMatcher.new("Que pasa?\n").matches?(proc).should == false
15
+ ComplainMatcher.new(/Que/).matches?(proc).should == true
16
+ ComplainMatcher.new(/Quoi/).matches?(proc).should == false
17
+ end
18
+
19
+ it "does not match when there is no output to $stderr" do
20
+ ComplainMatcher.new(nil).matches?(lambda {}).should == false
21
+ end
22
+
23
+ it "provides a useful failure message" do
24
+ matcher = ComplainMatcher.new(nil)
25
+ matcher.matches?(lambda { })
26
+ matcher.failure_message.should == ["Expected a warning", "but received none"]
27
+ matcher = ComplainMatcher.new("listen here")
28
+ matcher.matches?(lambda { warn "look out" })
29
+ matcher.failure_message.should ==
30
+ ["Expected warning: \"listen here\"", "but got: \"look out\""]
31
+ matcher = ComplainMatcher.new(/talk/)
32
+ matcher.matches?(lambda { warn "listen up" })
33
+ matcher.failure_message.should ==
34
+ ["Expected warning to match:", "/talk/"]
35
+ end
36
+
37
+ it "provides a useful negative failure message" do
38
+ proc = lambda { warn "ouch" }
39
+ matcher = ComplainMatcher.new(nil)
40
+ matcher.matches?(proc)
41
+ matcher.negative_failure_message.should ==
42
+ ["Unexpected warning: ", "\"ouch\""]
43
+ matcher = ComplainMatcher.new("ouchy")
44
+ matcher.matches?(proc)
45
+ matcher.negative_failure_message.should ==
46
+ ["Expected warning: \"ouchy\"", "but got: \"ouch\""]
47
+ matcher = ComplainMatcher.new(/ou/)
48
+ matcher.matches?(proc)
49
+ matcher.negative_failure_message.should ==
50
+ ["Expected warning not to match:", "/ou/"]
51
+ end
52
+ end
@@ -0,0 +1,33 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/expectations/expectations'
3
+ require 'mspec/matchers/eql'
4
+
5
+ describe EqlMatcher do
6
+ it "matches when actual is eql? to expected" do
7
+ EqlMatcher.new(1).matches?(1).should == true
8
+ EqlMatcher.new(1.5).matches?(1.5).should == true
9
+ EqlMatcher.new("red").matches?("red").should == true
10
+ EqlMatcher.new(:blue).matches?(:blue).should == true
11
+ EqlMatcher.new(Object).matches?(Object).should == true
12
+
13
+ o = Object.new
14
+ EqlMatcher.new(o).matches?(o).should == true
15
+ end
16
+
17
+ it "does not match when actual is not eql? to expected" do
18
+ EqlMatcher.new(1).matches?(1.0).should == false
19
+ EqlMatcher.new(Hash).matches?(Object).should == false
20
+ end
21
+
22
+ it "provides a useful failure message" do
23
+ matcher = EqlMatcher.new("red")
24
+ matcher.matches?("red")
25
+ matcher.failure_message.should == ["Expected \"red\"", "to have same value and type as \"red\""]
26
+ end
27
+
28
+ it "provides a useful negative failure message" do
29
+ matcher = EqlMatcher.new(1)
30
+ matcher.matches?(1.0)
31
+ matcher.negative_failure_message.should == ["Expected 1.0", "not to have same value or type as 1"]
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/expectations/expectations'
3
+ require 'mspec/matchers/equal'
4
+
5
+ describe EqualMatcher do
6
+ it "matches when actual is equal? to expected" do
7
+ EqualMatcher.new(1).matches?(1).should == true
8
+ EqualMatcher.new(:blue).matches?(:blue).should == true
9
+ EqualMatcher.new(Object).matches?(Object).should == true
10
+
11
+ o = Object.new
12
+ EqualMatcher.new(o).matches?(o).should == true
13
+ end
14
+
15
+ it "does not match when actual is not a equal? to expected" do
16
+ EqualMatcher.new(1).matches?(1.0).should == false
17
+ EqualMatcher.new(1.5).matches?(1.5).should == false
18
+ EqualMatcher.new("blue").matches?("blue").should == false
19
+ EqualMatcher.new(Hash).matches?(Object).should == false
20
+ end
21
+
22
+ it "provides a useful failure message" do
23
+ matcher = EqualMatcher.new("red")
24
+ matcher.matches?("red")
25
+ matcher.failure_message.should == ["Expected \"red\"", "to be identical to \"red\""]
26
+ end
27
+
28
+ it "provides a useful negative failure message" do
29
+ matcher = EqualMatcher.new(1)
30
+ matcher.matches?(1)
31
+ matcher.negative_failure_message.should == ["Expected 1", "not to be identical to 1"]
32
+ end
33
+ end
@@ -0,0 +1,47 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/expectations/expectations'
3
+ require 'mspec/matchers/equal_utf16'
4
+
5
+ describe EqualUtf16Matcher do
6
+ it "when given strings, matches when actual == expected" do
7
+ EqualUtf16Matcher.new("abcd").matches?("abcd").should == true
8
+ end
9
+
10
+ it "when given strings, matches when actual == expected, with byte order reversed" do
11
+ EqualUtf16Matcher.new("abcd").matches?("badc").should == true
12
+ end
13
+
14
+ it "when given arrays, matches when actual == expected" do
15
+ EqualUtf16Matcher.new(["abcd"]).matches?(["abcd"]).should == true
16
+ EqualUtf16Matcher.new(["abcd", "efgh"]).matches?(["abcd", "efgh"]).should == true
17
+ end
18
+
19
+ it "when given arrays, matches when actual == a version of expected with byte order reversed for all strings contained" do
20
+ EqualUtf16Matcher.new(["abcd"]).matches?(["badc"]).should == true
21
+ EqualUtf16Matcher.new(["abcd", "efgh"]).matches?(["badc", "fehg"]).should == true
22
+ end
23
+
24
+ it "when given strings, does not match when actual != expected AND != expected with byte order reversed" do
25
+ EqualUtf16Matcher.new("abcd").matches?("").should == false
26
+ EqualUtf16Matcher.new("abcd").matches?(nil).should == false
27
+ EqualUtf16Matcher.new("abcd").matches?("acbd").should == false
28
+ end
29
+
30
+ it "when given arrays, does not match when actual is not == expected or == a version of expected with byte order reversed for all strings contained simultaneously" do
31
+ EqualUtf16Matcher.new(["abcd"]).matches?([]).should == false
32
+ EqualUtf16Matcher.new(["abcd"]).matches?(["dcba"]).should == false
33
+ EqualUtf16Matcher.new(["abcd", "efgh"]).matches?(["abcd", "fehg"]).should == false
34
+ end
35
+
36
+ it "provides a useful failure message" do
37
+ matcher = EqualUtf16Matcher.new("a\0b\0")
38
+ matcher.matches?("a\0b\0c\0")
39
+ matcher.failure_message.should == ["Expected \"a\\000b\\000c\\000\"", "to equal \"a\\000b\\000\" or \"\\000a\\000b\""]
40
+ end
41
+
42
+ it "provides a useful negative failure message" do
43
+ matcher = EqualUtf16Matcher.new("a\0b\0")
44
+ matcher.matches?("\0a\0b")
45
+ matcher.negative_failure_message.should == ["Expected \"\\000a\\000b\"", "not to equal \"a\\000b\\000\" nor \"\\000a\\000b\""]
46
+ end
47
+ end
@@ -0,0 +1,37 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/expectations/expectations'
3
+ require 'mspec/matchers/include'
4
+
5
+ describe IncludeMatcher do
6
+ it "matches when actual includes expected" do
7
+ IncludeMatcher.new(2).matches?([1,2,3]).should == true
8
+ IncludeMatcher.new("b").matches?("abc").should == true
9
+ end
10
+
11
+ it "does not match when actual does not include expected" do
12
+ IncludeMatcher.new(4).matches?([1,2,3]).should == false
13
+ IncludeMatcher.new("d").matches?("abc").should == false
14
+ end
15
+
16
+ it "matches when actual includes all expected" do
17
+ IncludeMatcher.new(3, 2, 1).matches?([1,2,3]).should == true
18
+ IncludeMatcher.new("a", "b", "c").matches?("abc").should == true
19
+ end
20
+
21
+ it "does not match when actual does not include all expected" do
22
+ IncludeMatcher.new(3, 2, 4).matches?([1,2,3]).should == false
23
+ IncludeMatcher.new("a", "b", "c", "d").matches?("abc").should == false
24
+ end
25
+
26
+ it "provides a useful failure message" do
27
+ matcher = IncludeMatcher.new(5, 2)
28
+ matcher.matches?([1,2,3])
29
+ matcher.failure_message.should == ["Expected [1, 2, 3]", "to include 5"]
30
+ end
31
+
32
+ it "provides a useful negative failure message" do
33
+ matcher = IncludeMatcher.new(1, 2, 3)
34
+ matcher.matches?([1,2,3])
35
+ matcher.negative_failure_message.should == ["Expected [1, 2, 3]", "not to include 3"]
36
+ end
37
+ end
@@ -0,0 +1,74 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/expectations/expectations'
3
+ require 'mspec/matchers/output'
4
+
5
+ describe OutputMatcher do
6
+ it "matches when executing the proc results in the expected output to $stdout" do
7
+ proc = Proc.new { puts "bang!" }
8
+ OutputMatcher.new("bang!\n", nil).matches?(proc).should == true
9
+ OutputMatcher.new("pop", nil).matches?(proc).should == false
10
+ OutputMatcher.new(/bang/, nil).matches?(proc).should == true
11
+ OutputMatcher.new(/po/, nil).matches?(proc).should == false
12
+ end
13
+
14
+ it "matches when executing the proc results in the expected output to $stderr" do
15
+ proc = Proc.new { $stderr.write "boom!" }
16
+ OutputMatcher.new(nil, "boom!").matches?(proc).should == true
17
+ OutputMatcher.new(nil, "fizzle").matches?(proc).should == false
18
+ OutputMatcher.new(nil, /boom/).matches?(proc).should == true
19
+ OutputMatcher.new(nil, /fizzl/).matches?(proc).should == false
20
+ end
21
+
22
+ it "provides a useful failure message" do
23
+ proc = Proc.new { puts "unexpected"; $stderr.puts "unerror" }
24
+ matcher = OutputMatcher.new("expected", "error")
25
+ matcher.matches?(proc)
26
+ matcher.failure_message.should ==
27
+ ["Expected:\n $stdout: \"expected\"\n $stderr: \"error\"\n",
28
+ " got:\n $stdout: \"unexpected\"\n $stderr: \"unerror\"\n"]
29
+ matcher = OutputMatcher.new("expected", nil)
30
+ matcher.matches?(proc)
31
+ matcher.failure_message.should ==
32
+ ["Expected:\n $stdout: \"expected\"\n",
33
+ " got:\n $stdout: \"unexpected\"\n"]
34
+ matcher = OutputMatcher.new(nil, "error")
35
+ matcher.matches?(proc)
36
+ matcher.failure_message.should ==
37
+ ["Expected:\n $stderr: \"error\"\n",
38
+ " got:\n $stderr: \"unerror\"\n"]
39
+ matcher = OutputMatcher.new(/base/, nil)
40
+ matcher.matches?(proc)
41
+ matcher.failure_message.should ==
42
+ ["Expected:\n $stdout: /base/\n",
43
+ " got:\n $stdout: \"unexpected\"\n"]
44
+ matcher = OutputMatcher.new(nil, /octave/)
45
+ matcher.matches?(proc)
46
+ matcher.failure_message.should ==
47
+ ["Expected:\n $stderr: /octave/\n",
48
+ " got:\n $stderr: \"unerror\"\n"]
49
+ end
50
+
51
+ it "provides a useful negative failure message" do
52
+ proc = Proc.new { puts "expected"; $stderr.puts "error" }
53
+ matcher = OutputMatcher.new("expected", "error")
54
+ matcher.matches?(proc)
55
+ matcher.negative_failure_message.should ==
56
+ ["Expected output not to be:\n", " $stdout: \"expected\"\n $stderr: \"error\"\n"]
57
+ matcher = OutputMatcher.new("expected", nil)
58
+ matcher.matches?(proc)
59
+ matcher.negative_failure_message.should ==
60
+ ["Expected output not to be:\n", " $stdout: \"expected\"\n"]
61
+ matcher = OutputMatcher.new(nil, "error")
62
+ matcher.matches?(proc)
63
+ matcher.negative_failure_message.should ==
64
+ ["Expected output not to be:\n", " $stderr: \"error\"\n"]
65
+ matcher = OutputMatcher.new(/expect/, nil)
66
+ matcher.matches?(proc)
67
+ matcher.negative_failure_message.should ==
68
+ ["Expected output not to be:\n", " $stdout: \"expected\"\n"]
69
+ matcher = OutputMatcher.new(nil, /err/)
70
+ matcher.matches?(proc)
71
+ matcher.negative_failure_message.should ==
72
+ ["Expected output not to be:\n", " $stderr: \"error\"\n"]
73
+ end
74
+ end
@@ -0,0 +1,33 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/expectations/expectations'
3
+ require 'mspec/matchers/output_to_fd'
4
+
5
+ describe OutputToFDMatcher do
6
+ # Figure out how in the hell to achieve this
7
+ it "matches when running the block produces the expected output to the given FD" do
8
+ output_to_fd("Hi\n", STDERR).matches?(lambda { $stderr.print "Hi\n" }).should == true
9
+ end
10
+
11
+ it "does not match if running the block does not produce the expected output to the FD" do
12
+ output_to_fd("Hi\n", STDERR).matches?(lambda { $stderr.puts("Hello\n") }).should == false
13
+ end
14
+
15
+ it "defaults to matching against STDOUT" do
16
+ output_to_fd("Hi\n").matches?(lambda { $stdout.print "Hi\n" }).should == true
17
+ end
18
+
19
+ it "accepts any IO instance" do
20
+ io = IO.new STDOUT.fileno
21
+ output_to_fd("Hi\n", io).matches?(lambda { io.print "Hi\n" }).should == true
22
+ end
23
+
24
+ it "allows matching with a Regexp" do
25
+ s = "Hi there\n"
26
+ output_to_fd(/Hi/, STDERR).matches?(lambda { $stderr.print s }).should == true
27
+ output_to_fd(/Hi?/, STDERR).matches?(lambda { $stderr.print s }).should == true
28
+ output_to_fd(/[hH]i?/, STDERR).matches?(lambda { $stderr.print s }).should == true
29
+ output_to_fd(/.*/, STDERR).matches?(lambda { $stderr.print s }).should == true
30
+ output_to_fd(/H.*?here/, STDERR).matches?(lambda { $stderr.print s }).should == true
31
+ output_to_fd(/Ahoy/, STDERR).matches?(lambda { $stderr.print s }).should == false
32
+ end
33
+ end
@@ -0,0 +1,56 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/expectations/expectations'
3
+ require 'mspec/matchers/raise_error'
4
+
5
+ class ExpectedException < Exception; end
6
+ class UnexpectedException < Exception; end
7
+
8
+ describe RaiseErrorMatcher do
9
+ it "matches when the proc raises the expected exception" do
10
+ proc = Proc.new { raise ExpectedException }
11
+ RaiseErrorMatcher.new(ExpectedException, nil).matches?(proc).should == true
12
+ end
13
+
14
+ it "executes it's optional block if matched" do
15
+ run = false
16
+ proc = Proc.new { raise ExpectedException }
17
+ matcher = RaiseErrorMatcher.new(ExpectedException, nil) { |error|
18
+ run = true
19
+ error.class.should == ExpectedException
20
+ }
21
+
22
+ matcher.matches?(proc).should == true
23
+ run.should == true
24
+ end
25
+
26
+ it "matches when the proc raises the expected exception with the expected message" do
27
+ proc = Proc.new { raise ExpectedException, "message" }
28
+ RaiseErrorMatcher.new(ExpectedException, "message").matches?(proc).should == true
29
+ end
30
+
31
+ it "does not match when the proc does not raise the expected exception" do
32
+ proc = Proc.new { raise UnexpectedException }
33
+ RaiseErrorMatcher.new(ExpectedException, nil).matches?(proc).should == false
34
+ end
35
+
36
+ it "does not match when the proc raises the expected exception with an unexpected message" do
37
+ proc = Proc.new { raise UnexpectedException, "unexpected" }
38
+ RaiseErrorMatcher.new(ExpectedException, "expected").matches?(proc).should == false
39
+ end
40
+
41
+ it "provides a useful failure message" do
42
+ proc = Proc.new { raise UnexpectedException, "unexpected" }
43
+ matcher = RaiseErrorMatcher.new(ExpectedException, "expected")
44
+ matcher.matches?(proc)
45
+ matcher.failure_message.should ==
46
+ ["Expected ExpectedException (expected)", "but got UnexpectedException (unexpected)"]
47
+ end
48
+
49
+ it "provides a useful negative failure message" do
50
+ proc = Proc.new { raise ExpectedException, "expected" }
51
+ matcher = RaiseErrorMatcher.new(ExpectedException, "expected")
52
+ matcher.matches?(proc)
53
+ matcher.negative_failure_message.should ==
54
+ ["Expected to not get ExpectedException (expected)", ""]
55
+ end
56
+ end