rsanheim-micronaut 0.1.3.2

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.
Files changed (82) hide show
  1. data/LICENSE +45 -0
  2. data/README +17 -0
  3. data/RSPEC-LICENSE +23 -0
  4. data/Rakefile +83 -0
  5. data/bin/micronaut +4 -0
  6. data/examples/example_helper.rb +36 -0
  7. data/examples/lib/micronaut/behaviour_example.rb +188 -0
  8. data/examples/lib/micronaut/configuration_example.rb +70 -0
  9. data/examples/lib/micronaut/example_example.rb +46 -0
  10. data/examples/lib/micronaut/expectations/extensions/object_example.rb +72 -0
  11. data/examples/lib/micronaut/expectations/fail_with_example.rb +17 -0
  12. data/examples/lib/micronaut/expectations/wrap_expectation_example.rb +31 -0
  13. data/examples/lib/micronaut/formatters/base_formatter_example.rb +107 -0
  14. data/examples/lib/micronaut/formatters/documentation_formatter_example.rb +5 -0
  15. data/examples/lib/micronaut/formatters/progress_formatter_example.rb +74 -0
  16. data/examples/lib/micronaut/kernel_extensions_example.rb +13 -0
  17. data/examples/lib/micronaut/matchers/be_close_example.rb +52 -0
  18. data/examples/lib/micronaut/matchers/be_example.rb +298 -0
  19. data/examples/lib/micronaut/matchers/change_example.rb +360 -0
  20. data/examples/lib/micronaut/matchers/description_generation_example.rb +175 -0
  21. data/examples/lib/micronaut/matchers/eql_example.rb +35 -0
  22. data/examples/lib/micronaut/matchers/equal_example.rb +35 -0
  23. data/examples/lib/micronaut/matchers/handler_example.rb +153 -0
  24. data/examples/lib/micronaut/matchers/has_example.rb +71 -0
  25. data/examples/lib/micronaut/matchers/have_example.rb +575 -0
  26. data/examples/lib/micronaut/matchers/include_example.rb +103 -0
  27. data/examples/lib/micronaut/matchers/match_example.rb +43 -0
  28. data/examples/lib/micronaut/matchers/matcher_methods_example.rb +66 -0
  29. data/examples/lib/micronaut/matchers/operator_matcher_example.rb +189 -0
  30. data/examples/lib/micronaut/matchers/raise_error_example.rb +346 -0
  31. data/examples/lib/micronaut/matchers/respond_to_example.rb +54 -0
  32. data/examples/lib/micronaut/matchers/satisfy_example.rb +36 -0
  33. data/examples/lib/micronaut/matchers/simple_matcher_example.rb +93 -0
  34. data/examples/lib/micronaut/matchers/throw_symbol_example.rb +96 -0
  35. data/examples/lib/micronaut/runner_example.rb +5 -0
  36. data/examples/lib/micronaut/runner_options_example.rb +5 -0
  37. data/examples/lib/micronaut/world_example.rb +102 -0
  38. data/examples/lib/micronaut_example.rb +23 -0
  39. data/examples/resources/example_classes.rb +67 -0
  40. data/lib/autotest/discover.rb +3 -0
  41. data/lib/autotest/micronaut.rb +47 -0
  42. data/lib/micronaut/behaviour.rb +211 -0
  43. data/lib/micronaut/configuration.rb +133 -0
  44. data/lib/micronaut/example.rb +28 -0
  45. data/lib/micronaut/expectations/extensions/object.rb +62 -0
  46. data/lib/micronaut/expectations/extensions/string_and_symbol.rb +19 -0
  47. data/lib/micronaut/expectations/handler.rb +52 -0
  48. data/lib/micronaut/expectations/wrap_expectation.rb +57 -0
  49. data/lib/micronaut/expectations.rb +46 -0
  50. data/lib/micronaut/formatters/base_formatter.rb +82 -0
  51. data/lib/micronaut/formatters/base_text_formatter.rb +148 -0
  52. data/lib/micronaut/formatters/documentation_formatter.rb +62 -0
  53. data/lib/micronaut/formatters/progress_formatter.rb +36 -0
  54. data/lib/micronaut/formatters.rb +12 -0
  55. data/lib/micronaut/kernel_extensions.rb +11 -0
  56. data/lib/micronaut/matchers/be.rb +204 -0
  57. data/lib/micronaut/matchers/be_close.rb +22 -0
  58. data/lib/micronaut/matchers/change.rb +148 -0
  59. data/lib/micronaut/matchers/eql.rb +26 -0
  60. data/lib/micronaut/matchers/equal.rb +26 -0
  61. data/lib/micronaut/matchers/generated_descriptions.rb +36 -0
  62. data/lib/micronaut/matchers/has.rb +19 -0
  63. data/lib/micronaut/matchers/have.rb +153 -0
  64. data/lib/micronaut/matchers/include.rb +80 -0
  65. data/lib/micronaut/matchers/match.rb +22 -0
  66. data/lib/micronaut/matchers/method_missing.rb +9 -0
  67. data/lib/micronaut/matchers/operator_matcher.rb +50 -0
  68. data/lib/micronaut/matchers/raise_error.rb +128 -0
  69. data/lib/micronaut/matchers/respond_to.rb +50 -0
  70. data/lib/micronaut/matchers/satisfy.rb +50 -0
  71. data/lib/micronaut/matchers/simple_matcher.rb +135 -0
  72. data/lib/micronaut/matchers/throw_symbol.rb +108 -0
  73. data/lib/micronaut/matchers.rb +148 -0
  74. data/lib/micronaut/mocking/with_absolutely_nothing.rb +11 -0
  75. data/lib/micronaut/mocking/with_mocha.rb +13 -0
  76. data/lib/micronaut/mocking/with_rr.rb +24 -0
  77. data/lib/micronaut/mocking.rb +7 -0
  78. data/lib/micronaut/runner.rb +57 -0
  79. data/lib/micronaut/runner_options.rb +33 -0
  80. data/lib/micronaut/world.rb +75 -0
  81. data/lib/micronaut.rb +37 -0
  82. metadata +149 -0
@@ -0,0 +1,153 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
2
+
3
+ module ExampleExpectations
4
+
5
+ class ArbitraryMatcher
6
+ def initialize(*args, &block)
7
+ if args.last.is_a? Hash
8
+ @expected = args.last[:expected]
9
+ end
10
+ if block_given?
11
+ @expected = block.call
12
+ end
13
+ @block = block
14
+ end
15
+
16
+ def matches?(target)
17
+ @target = target
18
+ return @expected == target
19
+ end
20
+
21
+ def with(new_value)
22
+ @expected = new_value
23
+ self
24
+ end
25
+
26
+ def failure_message
27
+ "expected #{@expected}, got #{@target}"
28
+ end
29
+
30
+ def negative_failure_message
31
+ "expected not #{@expected}, got #{@target}"
32
+ end
33
+ end
34
+
35
+ class PositiveOnlyMatcher < ArbitraryMatcher
36
+ undef negative_failure_message rescue nil
37
+ end
38
+
39
+ def arbitrary_matcher(*args, &block)
40
+ ArbitraryMatcher.new(*args, &block)
41
+ end
42
+
43
+ def positive_only_matcher(*args, &block)
44
+ PositiveOnlyMatcher.new(*args, &block)
45
+ end
46
+
47
+ end
48
+
49
+ describe Micronaut::Expectations::ExpectationMatcherHandler do
50
+
51
+ describe "#handle_matcher" do
52
+
53
+ it "should ask the matcher if it matches" do
54
+ matcher = mock("matcher")
55
+ actual = Object.new
56
+ matcher.expects(:matches?).with(actual).returns(true)
57
+ Micronaut::Expectations::ExpectationMatcherHandler.handle_matcher(actual, matcher)
58
+ end
59
+
60
+ it "should explain when the matcher parameter is not a matcher" do
61
+ begin
62
+ nonmatcher = mock("nonmatcher")
63
+ actual = Object.new
64
+ Micronaut::Expectations::ExpectationMatcherHandler.handle_matcher(actual, nonmatcher)
65
+ rescue Micronaut::Expectations::InvalidMatcherError => e
66
+ end
67
+
68
+ e.message.should =~ /^Expected a matcher, got /
69
+ end
70
+
71
+ it "should return the match value" do
72
+ matcher = mock("matcher")
73
+ actual = Object.new
74
+ matcher.expects(:matches?).with(actual).returns(:this_value)
75
+ Micronaut::Expectations::ExpectationMatcherHandler.handle_matcher(actual, matcher).should == :this_value
76
+ end
77
+
78
+ end
79
+
80
+ end
81
+
82
+ describe Micronaut::Expectations::NegativeExpectationMatcherHandler do
83
+
84
+ describe "#handle_matcher" do
85
+
86
+ it "should explain when matcher does not support should_not" do
87
+ matcher = mock("matcher")
88
+ matcher.stubs(:matches?)
89
+ actual = Object.new
90
+ lambda {
91
+ Micronaut::Expectations::NegativeExpectationMatcherHandler.handle_matcher(actual, matcher)
92
+ }.should fail_with(/Matcher does not support should_not.\n/)
93
+ end
94
+
95
+ it "should ask the matcher if it matches" do
96
+ matcher = mock("matcher")
97
+ actual = Object.new
98
+ matcher.stubs(:negative_failure_message)
99
+ matcher.expects(:matches?).with(actual).returns(false)
100
+ Micronaut::Expectations::NegativeExpectationMatcherHandler.handle_matcher(actual, matcher)
101
+ end
102
+
103
+ it "should explain when the matcher parameter is not a matcher" do
104
+ begin
105
+ nonmatcher = mock("nonmatcher")
106
+ actual = Object.new
107
+ Micronaut::Expectations::NegativeExpectationMatcherHandler.handle_matcher(actual, nonmatcher)
108
+ rescue Micronaut::Expectations::InvalidMatcherError => e
109
+ end
110
+
111
+ e.message.should =~ /^Expected a matcher, got /
112
+ end
113
+
114
+
115
+ it "should return the match value" do
116
+ matcher = mock("matcher")
117
+ actual = Object.new
118
+ matcher.expects(:matches?).with(actual).returns(false)
119
+ matcher.stubs(:negative_failure_message).returns("ignore")
120
+ Micronaut::Expectations::NegativeExpectationMatcherHandler.handle_matcher(actual, matcher).should be_false
121
+ end
122
+
123
+ end
124
+
125
+ end
126
+
127
+ describe Micronaut::Expectations::ExpectationMatcherHandler do
128
+ include ExampleExpectations
129
+
130
+ it "should handle submitted args" do
131
+ 5.should arbitrary_matcher(:expected => 5)
132
+ 5.should arbitrary_matcher(:expected => "wrong").with(5)
133
+ lambda { 5.should arbitrary_matcher(:expected => 4) }.should fail_with("expected 4, got 5")
134
+ lambda { 5.should arbitrary_matcher(:expected => 5).with(4) }.should fail_with("expected 4, got 5")
135
+ 5.should_not arbitrary_matcher(:expected => 4)
136
+ 5.should_not arbitrary_matcher(:expected => 5).with(4)
137
+ lambda { 5.should_not arbitrary_matcher(:expected => 5) }.should fail_with("expected not 5, got 5")
138
+ lambda { 5.should_not arbitrary_matcher(:expected => 4).with(5) }.should fail_with("expected not 5, got 5")
139
+ end
140
+
141
+ it "should handle the submitted block" do
142
+ 5.should arbitrary_matcher { 5 }
143
+ 5.should arbitrary_matcher(:expected => 4) { 5 }
144
+ 5.should arbitrary_matcher(:expected => 4).with(5) { 3 }
145
+ end
146
+
147
+ it "should explain when matcher does not support should_not" do
148
+ lambda {
149
+ 5.should_not positive_only_matcher(:expected => 5)
150
+ }.should fail_with(/Matcher does not support should_not.\n/)
151
+ end
152
+
153
+ end
@@ -0,0 +1,71 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
2
+
3
+ describe Micronaut::Matchers do
4
+
5
+ describe "should have_sym(*args)" do
6
+
7
+ it "should pass if #has_sym?(*args) returns true" do
8
+ {:a => "A"}.should have_key(:a)
9
+ end
10
+
11
+ it "should fail if #has_sym?(*args) returns false" do
12
+ lambda {
13
+ {:b => "B"}.should have_key(:a)
14
+ }.should fail_with("expected #has_key?(:a) to return true, got false")
15
+ end
16
+
17
+ it "should fail if target does not respond to #has_sym?" do
18
+ lambda {
19
+ Object.new.should have_key(:a)
20
+ }.should raise_error(NoMethodError)
21
+ end
22
+
23
+ it "should reraise an exception thrown in #has_sym?(*args)" do
24
+ o = Object.new
25
+ def o.has_sym?(*args)
26
+ raise "Funky exception"
27
+ end
28
+ lambda { o.should have_sym(:foo) }.should raise_error("Funky exception")
29
+ end
30
+
31
+ end
32
+
33
+ describe "should_not have_sym(*args)" do
34
+
35
+ it "should pass if #has_sym?(*args) returns false" do
36
+ {:a => "A"}.should_not have_key(:b)
37
+ end
38
+
39
+ it "should fail if #has_sym?(*args) returns true" do
40
+ lambda {
41
+ {:a => "A"}.should_not have_key(:a)
42
+ }.should fail_with("expected #has_key?(:a) to return false, got true")
43
+ end
44
+
45
+ it "should fail if target does not respond to #has_sym?" do
46
+ lambda {
47
+ Object.new.should have_key(:a)
48
+ }.should raise_error(NoMethodError)
49
+ end
50
+
51
+ it "should reraise an exception thrown in #has_sym?(*args)" do
52
+ o = Object.new
53
+ def o.has_sym?(*args)
54
+ raise "Funky exception"
55
+ end
56
+ lambda { o.should_not have_sym(:foo) }.should raise_error("Funky exception")
57
+ end
58
+
59
+ end
60
+
61
+ describe "has" do
62
+
63
+ it "should work when the target implements #send" do
64
+ o = {:a => "A"}
65
+ def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
66
+ lambda { o.should have_key(:a) }.should_not raise_error
67
+ end
68
+
69
+ end
70
+
71
+ end