spicycode-micronaut 0.0.7 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. data/Rakefile +1 -1
  2. data/examples/lib/micronaut/{behaviour_group_example.rb → behaviour_example.rb} +15 -13
  3. data/examples/lib/micronaut/configuration_example.rb +4 -4
  4. data/examples/lib/micronaut/example_example.rb +46 -0
  5. data/examples/lib/micronaut/expectations/extensions/object_example.rb +63 -76
  6. data/examples/lib/micronaut/expectations/wrap_expectation_example.rb +4 -3
  7. data/examples/lib/micronaut/formatters/base_formatter_example.rb +2 -2
  8. data/examples/lib/micronaut/formatters/documentation_formatter_example.rb +5 -0
  9. data/examples/lib/micronaut/formatters/progress_formatter_example.rb +8 -29
  10. data/examples/lib/micronaut/matchers/be_close_example.rb +48 -38
  11. data/examples/lib/micronaut/matchers/be_example.rb +287 -246
  12. data/examples/lib/micronaut/matchers/change_example.rb +306 -275
  13. data/examples/lib/micronaut/matchers/description_generation_example.rb +168 -160
  14. data/examples/lib/micronaut/matchers/eql_example.rb +30 -24
  15. data/examples/lib/micronaut/matchers/equal_example.rb +31 -25
  16. data/examples/lib/micronaut/matchers/handler_example.rb +36 -29
  17. data/examples/lib/micronaut/matchers/has_example.rb +57 -49
  18. data/examples/lib/micronaut/matchers/include_example.rb +89 -74
  19. data/examples/lib/micronaut/matchers/match_example.rb +33 -29
  20. data/examples/lib/micronaut/world_example.rb +4 -4
  21. data/lib/micronaut/{behaviour_group.rb → behaviour.rb} +8 -7
  22. data/lib/micronaut/configuration.rb +1 -1
  23. data/lib/micronaut/example.rb +5 -1
  24. data/lib/micronaut/formatters/base_formatter.rb +6 -6
  25. data/lib/micronaut/formatters/base_text_formatter.rb +8 -13
  26. data/lib/micronaut/formatters/documentation_formatter.rb +62 -0
  27. data/lib/micronaut/formatters/progress_formatter.rb +1 -0
  28. data/lib/micronaut/formatters.rb +1 -0
  29. data/lib/micronaut/kernel_extensions.rb +1 -1
  30. data/lib/micronaut/runner.rb +1 -4
  31. data/lib/micronaut/runner_options.rb +11 -4
  32. data/lib/micronaut.rb +2 -2
  33. metadata +7 -4
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rubygems/specification'
4
4
  require 'date'
5
5
 
6
6
  GEM = "micronaut"
7
- GEM_VERSION = "0.0.7"
7
+ GEM_VERSION = "0.0.9"
8
8
  AUTHOR = "Chad Humphries"
9
9
  EMAIL = "chad@spicycode.com"
10
10
  HOMEPAGE = "http://spicycode.com"
@@ -1,33 +1,34 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../../example_helper")
2
2
 
3
- describe Micronaut::BehaviourGroup do
3
+ describe Micronaut::Behaviour do
4
4
 
5
5
  class Foo
6
6
 
7
7
  end
8
8
 
9
9
  def empty_behaviour_group
10
- Micronaut::BehaviourGroup.describe(Foo, 'Empty Behaviour Group') { }
10
+ group = Micronaut::Behaviour.describe(Foo, 'Empty Behaviour Group') { }
11
+ remove_last_describe_from_world
11
12
  end
12
13
 
13
14
  describe "describing behaviour with #describe" do
14
15
 
15
16
  it "should raise an ArgumentError if no name is given" do
16
- lambda { Micronaut::BehaviourGroup.describe() {} }.should raise_error(ArgumentError)
17
+ lambda { Micronaut::Behaviour.describe() {} }.should raise_error(ArgumentError)
17
18
  end
18
19
 
19
20
  it "should raise an ArgumentError if no block is given" do
20
- lambda { Micronaut::BehaviourGroup.describe('foo') }.should raise_error(ArgumentError)
21
+ lambda { Micronaut::Behaviour.describe('foo') }.should raise_error(ArgumentError)
21
22
  end
22
23
 
23
24
  describe '#name' do
24
25
 
25
26
  it "should expose the first parameter as name" do
26
- Micronaut::BehaviourGroup.describe("my favorite pony") { }.name.should == 'my favorite pony'
27
+ Micronaut::Behaviour.describe("my favorite pony") { }.name.should == 'my favorite pony'
27
28
  end
28
29
 
29
30
  it "should call to_s on the first parameter in case it is a constant" do
30
- Micronaut::BehaviourGroup.describe(Foo) { }.name.should == 'Foo'
31
+ Micronaut::Behaviour.describe(Foo) { }.name.should == 'Foo'
31
32
  end
32
33
 
33
34
  end
@@ -35,11 +36,11 @@ describe Micronaut::BehaviourGroup do
35
36
  describe '#described_type' do
36
37
 
37
38
  it "should be the first parameter when it is a constant" do
38
- Micronaut::BehaviourGroup.describe(Foo) { }.described_type.should == Foo
39
+ Micronaut::Behaviour.describe(Foo) { }.described_type.should == Foo
39
40
  end
40
41
 
41
42
  it "should be nil when the first parameter is a string" do
42
- Micronaut::BehaviourGroup.describe("i'm a computer") { }.described_type.should be_nil
43
+ Micronaut::Behaviour.describe("i'm a computer") { }.described_type.should be_nil
43
44
  end
44
45
 
45
46
  end
@@ -47,11 +48,11 @@ describe Micronaut::BehaviourGroup do
47
48
  describe '#description' do
48
49
 
49
50
  it "should expose the second parameter as description" do
50
- Micronaut::BehaviourGroup.describe(Foo, "my desc") { }.description.should == 'my desc'
51
+ Micronaut::Behaviour.describe(Foo, "my desc") { }.description.should == 'my desc'
51
52
  end
52
53
 
53
54
  it "should allow the second parameter to be nil" do
54
- Micronaut::BehaviourGroup.describe(Foo, nil) { }.description.size.should == 0
55
+ Micronaut::Behaviour.describe(Foo, nil) { }.description.size.should == 0
55
56
  end
56
57
 
57
58
  end
@@ -59,11 +60,11 @@ describe Micronaut::BehaviourGroup do
59
60
  describe '#options' do
60
61
 
61
62
  it "should expose the third parameter as options" do
62
- Micronaut::BehaviourGroup.describe(Foo, nil, 'foo' => 'bar') { }.options.should == { "foo" => 'bar' }
63
+ Micronaut::Behaviour.describe(Foo, nil, 'foo' => 'bar') { }.options.should == { "foo" => 'bar' }
63
64
  end
64
65
 
65
66
  it "should be an empty hash if no options are supplied" do
66
- Micronaut::BehaviourGroup.describe(Foo, nil) { }.options.should == {}
67
+ Micronaut::Behaviour.describe(Foo, nil) { }.options.should == {}
67
68
  end
68
69
 
69
70
  end
@@ -175,7 +176,8 @@ describe Micronaut::BehaviourGroup do
175
176
  describe "nested describes" do
176
177
 
177
178
  before { @wee += 5 }
178
- # it "should set the described type to the parent described type (if it is not given)"
179
+
180
+ it "should set the described type to the parent described type (if it is not given)"
179
181
 
180
182
  it "should have all of the parent before blocks" do
181
183
  @wee.should == 6
@@ -5,12 +5,12 @@ describe Micronaut::Configuration do
5
5
  describe "#mock_with" do
6
6
 
7
7
  it "should include the mocha adapter when called with :mocha" do
8
- Micronaut::BehaviourGroup.expects(:send).with(:include, Micronaut::Mocking::WithMocha)
8
+ Micronaut::Behaviour.expects(:send).with(:include, Micronaut::Mocking::WithMocha)
9
9
  Micronaut::Configuration.new.mock_with :mocha
10
10
  end
11
11
 
12
12
  it "should include the do absolutely nothing mocking adapter for all other cases" do
13
- Micronaut::BehaviourGroup.expects(:send).with(:include, Micronaut::Mocking::WithAbsolutelyNothing)
13
+ Micronaut::Behaviour.expects(:send).with(:include, Micronaut::Mocking::WithAbsolutelyNothing)
14
14
  Micronaut::Configuration.new.mock_with
15
15
  end
16
16
 
@@ -26,7 +26,7 @@ describe Micronaut::Configuration do
26
26
 
27
27
  it "should include the given module into each behaviour group" do
28
28
  Micronaut.configuration.include(InstanceLevelMethods)
29
- group = Micronaut::BehaviourGroup.describe(Object, 'does like, stuff and junk') { }
29
+ group = Micronaut::Behaviour.describe(Object, 'does like, stuff and junk') { }
30
30
  group.should_not respond_to(:you_call_this_a_blt?)
31
31
  remove_last_describe_from_world
32
32
 
@@ -47,7 +47,7 @@ describe Micronaut::Configuration do
47
47
 
48
48
  it "should extend the given module into each behaviour group" do
49
49
  Micronaut.configuration.extend(FocusedSupport)
50
- group = Micronaut::BehaviourGroup.describe(FocusedSupport, 'the focused support ') { }
50
+ group = Micronaut::Behaviour.describe(FocusedSupport, 'the focused support ') { }
51
51
  group.should respond_to(:fit)
52
52
  remove_last_describe_from_world
53
53
  end
@@ -0,0 +1,46 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../example_helper")
2
+
3
+ describe Micronaut::Example do
4
+
5
+ before do
6
+ behaviour = stub('behaviour', :name => 'behaviour_name')
7
+ @example = Micronaut::Example.new(behaviour, 'description', {}, (lambda {}))
8
+ end
9
+
10
+ describe "attr readers" do
11
+
12
+ it "should have one for the parent behaviour" do
13
+ @example.should respond_to(:behaviour)
14
+ end
15
+
16
+ it "should have one for it's description" do
17
+ @example.should respond_to(:description)
18
+ end
19
+
20
+ it "should have one for it's options" do
21
+ @example.should respond_to(:options)
22
+ end
23
+
24
+ it "should have one for it's block" do
25
+ @example.should respond_to(:example_block)
26
+ end
27
+
28
+ end
29
+
30
+ describe '#inspect' do
31
+
32
+ it "should return 'behaviour_name - description'" do
33
+ @example.inspect.should == 'behaviour_name - description'
34
+ end
35
+
36
+ end
37
+
38
+ describe '#to_s' do
39
+
40
+ it "should return #inspect" do
41
+ @example.to_s.should == @example.inspect
42
+ end
43
+
44
+ end
45
+
46
+ end
@@ -1,85 +1,72 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../../../../example_helper")
2
2
 
3
- describe Object, "#should" do
4
-
5
- before do
6
- @target = "target"
7
- @matcher = mock("matcher")
8
- @matcher.stubs(:matches?).returns(true)
9
- @matcher.stubs(:failure_message)
10
- end
11
-
12
- it "should accept and interact with a matcher" do
13
- @matcher.expects(:matches?).with(@target).returns(true)
14
- @target.should @matcher
15
- end
16
-
17
- it "should ask for a failure_message when matches? returns false" do
18
- @matcher.expects(:matches?).with(@target).returns(false)
19
- @matcher.expects(:failure_message).returns("the failure message")
20
- lambda {
3
+ describe Object do
4
+
5
+ describe "#should" do
6
+
7
+ before do
8
+ @target = "target"
9
+ @matcher = mock("matcher")
10
+ @matcher.stubs(:matches?).returns(true)
11
+ @matcher.stubs(:failure_message)
12
+ end
13
+
14
+ it "should accept and interact with a matcher" do
15
+ @matcher.expects(:matches?).with(@target).returns(true)
21
16
  @target.should @matcher
22
- }.should fail_with("the failure message")
23
- end
24
-
25
- it "should raise error if it receives false directly" do
26
- lambda {
27
- @target.should false
28
- }.should raise_error(Micronaut::Expectations::InvalidMatcherError)
29
- end
30
-
31
- it "should raise error if it receives false (evaluated)" do
32
- lambda {
33
- @target.should eql?("foo")
34
- }.should raise_error(Micronaut::Expectations::InvalidMatcherError)
35
- end
36
-
37
- it "should raise error if it receives true" do
38
- lambda {
39
- @target.should true
40
- }.should raise_error(Micronaut::Expectations::InvalidMatcherError)
41
- end
42
-
43
- end
44
-
45
- describe Object, "#should_not" do
46
-
47
- before do
48
- @target = "target"
49
- @matcher = mock("matcher")
50
- end
51
-
52
- it "should accept and interact with a matcher" do
53
- @matcher.expects(:matches?).with(@target).returns(false)
54
- @matcher.stubs(:negative_failure_message)
55
-
56
- @target.should_not @matcher
17
+ end
18
+
19
+ it "should ask for a failure_message when matches? returns false" do
20
+ @matcher.expects(:matches?).with(@target).returns(false)
21
+ @matcher.expects(:failure_message).returns("the failure message")
22
+ lambda { @target.should @matcher }.should fail_with("the failure message")
23
+ end
24
+
25
+ it "should raise error if it receives false directly" do
26
+ lambda { @target.should false }.should raise_error(Micronaut::Expectations::InvalidMatcherError)
27
+ end
28
+
29
+ it "should raise error if it receives false (evaluated)" do
30
+ lambda { @target.should eql?("foo") }.should raise_error(Micronaut::Expectations::InvalidMatcherError)
31
+ end
32
+
33
+ it "should raise error if it receives true" do
34
+ lambda { @target.should true }.should raise_error(Micronaut::Expectations::InvalidMatcherError)
35
+ end
36
+
57
37
  end
58
-
59
- it "should ask for a negative_failure_message when matches? returns true" do
60
- @matcher.expects(:matches?).with(@target).returns(true)
61
- @matcher.expects(:negative_failure_message).returns("the negative failure message")
62
- lambda {
38
+
39
+ describe "#should_not" do
40
+
41
+ before do
42
+ @target = "target"
43
+ @matcher = mock("matcher")
44
+ end
45
+
46
+ it "should accept and interact with a matcher" do
47
+ @matcher.expects(:matches?).with(@target).returns(false)
48
+ @matcher.stubs(:negative_failure_message)
63
49
  @target.should_not @matcher
64
- }.should fail_with("the negative failure message")
65
- end
50
+ end
51
+
52
+ it "should ask for a negative_failure_message when matches? returns true" do
53
+ @matcher.expects(:matches?).with(@target).returns(true)
54
+ @matcher.expects(:negative_failure_message).returns("the negative failure message")
55
+ lambda { @target.should_not @matcher }.should fail_with("the negative failure message")
56
+ end
57
+
58
+ it "should raise error if it receives false directly" do
59
+ lambda { @target.should_not false }.should raise_error(Micronaut::Expectations::InvalidMatcherError)
60
+ end
61
+
62
+ it "should raise error if it receives false (evaluated)" do
63
+ lambda { @target.should_not eql?("foo") }.should raise_error(Micronaut::Expectations::InvalidMatcherError)
64
+ end
65
+
66
+ it "should raise error if it receives true" do
67
+ lambda { @target.should_not true }.should raise_error(Micronaut::Expectations::InvalidMatcherError)
68
+ end
66
69
 
67
- it "should raise error if it receives false directly" do
68
- lambda {
69
- @target.should_not false
70
- }.should raise_error(Micronaut::Expectations::InvalidMatcherError)
71
- end
72
-
73
- it "should raise error if it receives false (evaluated)" do
74
- lambda {
75
- @target.should_not eql?("foo")
76
- }.should raise_error(Micronaut::Expectations::InvalidMatcherError)
77
- end
78
-
79
- it "should raise error if it receives true" do
80
- lambda {
81
- @target.should_not true
82
- }.should raise_error(Micronaut::Expectations::InvalidMatcherError)
83
70
  end
84
71
 
85
72
  end
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
2
2
 
3
- module Micronaut
4
- module Matchers
3
+ describe Micronaut::Matchers do
4
+
5
5
  describe "wrap_expectation" do
6
6
 
7
7
  def stub_matcher
@@ -25,6 +25,7 @@ module Micronaut
25
25
  raise "error"
26
26
  end.should be_false
27
27
  end
28
+
28
29
  end
29
- end
30
+
30
31
  end
@@ -68,8 +68,8 @@ describe Micronaut::Formatters::BaseFormatter do
68
68
  @formatter.should have_interface_for(:start).with(1).argument
69
69
  end
70
70
 
71
- it "should have add_example_group as an interface with one argument" do
72
- @formatter.should have_interface_for(:add_example_group).with(1).argument
71
+ it "should have add_behaviour as an interface with one argument" do
72
+ @formatter.should have_interface_for(:add_behaviour).with(1).argument
73
73
  end
74
74
 
75
75
  it "should have example_started as an interface with one argument" do
@@ -0,0 +1,5 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
2
+
3
+ describe Micronaut::Formatters::DocumentationFormatter do
4
+
5
+ end
@@ -20,10 +20,11 @@ describe Micronaut::Formatters::ProgressFormatter do
20
20
  end
21
21
 
22
22
  it "should produce standard summary" do
23
- example_group = Micronaut::BehaviourGroup.describe("example_group") do
23
+ behaviour = Micronaut::Behaviour.describe("behaviour") do
24
24
  it('example') {}
25
25
  end
26
- example = example_group.examples.first
26
+ remove_last_describe_from_world
27
+ example = behaviour.examples.first
27
28
  @formatter.example_pending(example, "message")
28
29
  @io.rewind
29
30
  @formatter.dump_summary(3, 2, 1, 1)
@@ -31,21 +32,18 @@ describe Micronaut::Formatters::ProgressFormatter do
31
32
  end
32
33
 
33
34
  it "should push green dot for passing spec" do
34
- @io.expects(:tty?).returns(true)
35
35
  @options.expects(:enable_color_in_output?).returns(true)
36
36
  @formatter.example_passed("spec")
37
37
  @io.string.should == "\e[32m.\e[0m"
38
38
  end
39
39
 
40
40
  it "should push red F for failure spec" do
41
- @io.expects(:tty?).returns(true)
42
41
  @options.expects(:enable_color_in_output?).returns(true)
43
42
  @formatter.example_failed("spec", Micronaut::Expectations::ExpectationNotMetError.new)
44
43
  @io.string.should eql("\e[31mF\e[0m")
45
44
  end
46
45
 
47
46
  it "should push magenta F for error spec" do
48
- @io.expects(:tty?).returns(true)
49
47
  @options.expects(:enable_color_in_output?).returns(true)
50
48
  @formatter.example_failed("spec", RuntimeError.new)
51
49
  @io.string.should eql("\e[35mF\e[0m")
@@ -59,36 +57,17 @@ describe Micronaut::Formatters::ProgressFormatter do
59
57
  it "should ensure two ':' in the first backtrace" do
60
58
  backtrace = ["/tmp/x.rb:1", "/tmp/x.rb:2", "/tmp/x.rb:3"]
61
59
  @formatter.format_backtrace(backtrace).should eql(<<-EOE.rstrip)
62
- /tmp/x.rb:1:
63
- /tmp/x.rb:2:
64
- /tmp/x.rb:3:
60
+ /tmp/x.rb:1
61
+ /tmp/x.rb:2
62
+ /tmp/x.rb:3
65
63
  EOE
66
64
 
67
65
  backtrace = ["/tmp/x.rb:1: message", "/tmp/x.rb:2", "/tmp/x.rb:3"]
68
66
  @formatter.format_backtrace(backtrace).should eql(<<-EOE.rstrip)
69
67
  /tmp/x.rb:1: message
70
- /tmp/x.rb:2:
71
- /tmp/x.rb:3:
68
+ /tmp/x.rb:2
69
+ /tmp/x.rb:3
72
70
  EOE
73
71
  end
74
72
 
75
- describe "outputting to custom out" do
76
- before do
77
- @out = mock("out")
78
- @options = mock('options')
79
- @out.stubs(:puts)
80
- @formatter = Micronaut::Formatters::ProgressFormatter.new(@options, @out)
81
- @formatter.class.__send__ :public, :output_to_tty?
82
- end
83
-
84
- after do
85
- @formatter.class.__send__ :protected, :output_to_tty?
86
- end
87
-
88
- it "should not throw NoMethodError on output_to_tty?" do
89
- @out.expects(:tty?).raises(NoMethodError)
90
- @formatter.output_to_tty?.should be_false
91
- end
92
- end
93
-
94
73
  end
@@ -1,42 +1,52 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
2
2
 
3
- module Micronaut
4
- module Matchers
5
- describe "be_close" do
6
- it "should match when value == target" do
7
- be_close(5.0, 0.5).matches?(5.0).should be_true
8
- end
9
- it "should match when value < (target + delta)" do
10
- be_close(5.0, 0.5).matches?(5.49).should be_true
11
- end
12
- it "should match when value > (target - delta)" do
13
- be_close(5.0, 0.5).matches?(4.51).should be_true
14
- end
15
- it "should not match when value == (target - delta)" do
16
- be_close(5.0, 0.5).matches?(4.5).should be_false
17
- end
18
- it "should not match when value < (target - delta)" do
19
- be_close(5.0, 0.5).matches?(4.49).should be_false
20
- end
21
- it "should not match when value == (target + delta)" do
22
- be_close(5.0, 0.5).matches?(5.5).should be_false
23
- end
24
- it "should not match when value > (target + delta)" do
25
- be_close(5.0, 0.5).matches?(5.51).should be_false
26
- end
27
- it "should provide a useful failure message" do
28
- #given
29
- matcher = be_close(5.0, 0.5)
30
- #when
31
- matcher.matches?(5.51)
32
- #then
33
- matcher.failure_message.should == "expected 5.0 +/- (< 0.5), got 5.51"
34
- end
35
- it "should describe itself" do
36
- matcher = be_close(5.0, 0.5)
37
- matcher.matches?(5.1)
38
- matcher.description.should == "be close to 5.0 (within +- 0.5)"
39
- end
3
+ describe Micronaut::Matchers do
4
+
5
+ describe "be_close" do
6
+
7
+ it "should match when value == target" do
8
+ be_close(5.0, 0.5).matches?(5.0).should be_true
9
+ end
10
+
11
+ it "should match when value < (target + delta)" do
12
+ be_close(5.0, 0.5).matches?(5.49).should be_true
13
+ end
14
+
15
+ it "should match when value > (target - delta)" do
16
+ be_close(5.0, 0.5).matches?(4.51).should be_true
17
+ end
18
+
19
+ it "should not match when value == (target - delta)" do
20
+ be_close(5.0, 0.5).matches?(4.5).should be_false
21
+ end
22
+
23
+ it "should not match when value < (target - delta)" do
24
+ be_close(5.0, 0.5).matches?(4.49).should be_false
40
25
  end
26
+
27
+ it "should not match when value == (target + delta)" do
28
+ be_close(5.0, 0.5).matches?(5.5).should be_false
29
+ end
30
+
31
+ it "should not match when value > (target + delta)" do
32
+ be_close(5.0, 0.5).matches?(5.51).should be_false
33
+ end
34
+
35
+ it "should provide a useful failure message" do
36
+ #given
37
+ matcher = be_close(5.0, 0.5)
38
+ #when
39
+ matcher.matches?(5.51)
40
+ #then
41
+ matcher.failure_message.should == "expected 5.0 +/- (< 0.5), got 5.51"
42
+ end
43
+
44
+ it "should describe itself" do
45
+ matcher = be_close(5.0, 0.5)
46
+ matcher.matches?(5.1)
47
+ matcher.description.should == "be close to 5.0 (within +- 0.5)"
48
+ end
49
+
41
50
  end
42
- end
51
+
52
+ end