spicycode-micronaut 0.0.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.
- data/LICENSE +20 -0
- data/README +17 -0
- data/Rakefile +55 -0
- data/examples/example_helper.rb +19 -0
- data/examples/lib/micronaut/example_group_example.rb +116 -0
- data/examples/lib/micronaut/example_runner_example.rb +5 -0
- data/examples/lib/micronaut/expectations/differs/default_example.rb +126 -0
- data/examples/lib/micronaut/expectations/extensions/object_example.rb +78 -0
- data/examples/lib/micronaut/expectations/fail_with_example.rb +71 -0
- data/examples/lib/micronaut/expectations/wrap_expectation_example.rb +30 -0
- data/examples/lib/micronaut_example.rb +8 -0
- data/lib/autotest/discover.rb +3 -0
- data/lib/autotest/micronaut.rb +43 -0
- data/lib/micronaut/example_group.rb +100 -0
- data/lib/micronaut/example_runner.rb +108 -0
- data/lib/micronaut/example_world.rb +13 -0
- data/lib/micronaut/exceptions.rb +7 -0
- data/lib/micronaut/expectations/differs/default.rb +67 -0
- data/lib/micronaut/expectations/handler.rb +52 -0
- data/lib/micronaut/expectations/object_extensions.rb +62 -0
- data/lib/micronaut/expectations/string_and_symbol_extensions.rb +17 -0
- data/lib/micronaut/expectations/wrap_expectation.rb +51 -0
- data/lib/micronaut/expectations.rb +57 -0
- data/lib/micronaut/extensions/kernel.rb +15 -0
- data/lib/micronaut/matchers/be.rb +203 -0
- data/lib/micronaut/matchers/be_close.rb +37 -0
- data/lib/micronaut/matchers/change.rb +148 -0
- data/lib/micronaut/matchers/eql.rb +43 -0
- data/lib/micronaut/matchers/equal.rb +43 -0
- data/lib/micronaut/matchers/errors.rb +5 -0
- data/lib/micronaut/matchers/exist.rb +22 -0
- data/lib/micronaut/matchers/generated_descriptions.rb +36 -0
- data/lib/micronaut/matchers/has.rb +34 -0
- data/lib/micronaut/matchers/have.rb +150 -0
- data/lib/micronaut/matchers/include.rb +77 -0
- data/lib/micronaut/matchers/match.rb +41 -0
- data/lib/micronaut/matchers/method_missing.rb +9 -0
- data/lib/micronaut/matchers/operator_matcher.rb +72 -0
- data/lib/micronaut/matchers/raise_error.rb +132 -0
- data/lib/micronaut/matchers/respond_to.rb +46 -0
- data/lib/micronaut/matchers/satisfy.rb +47 -0
- data/lib/micronaut/matchers/simple_matcher.rb +132 -0
- data/lib/micronaut/matchers/throw_symbol.rb +100 -0
- data/lib/micronaut/matchers.rb +141 -0
- data/lib/micronaut/mocking/with_mocha.rb +23 -0
- data/lib/micronaut.rb +42 -0
- metadata +120 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Chad Humphries
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= Micronaut
|
2
|
+
|
3
|
+
* http://github.com/spicycode/micronaut
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Micronaut is an ultra light-weight BDD test framework. For the moment think of it is a prototype of
|
8
|
+
RSpec lite. Definitely pre alpha at the moment.
|
9
|
+
|
10
|
+
== REQUIREMENTS:
|
11
|
+
|
12
|
+
+ Ruby 1.8
|
13
|
+
|
14
|
+
== CREDITS:
|
15
|
+
|
16
|
+
* Mini/Unit for the great ideas and runner
|
17
|
+
* RSpec for the great ideas and matchers
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'rubygems/specification'
|
4
|
+
require 'date'
|
5
|
+
|
6
|
+
GEM = "micronaut"
|
7
|
+
GEM_VERSION = "0.0.2"
|
8
|
+
AUTHOR = "Chad Humphries"
|
9
|
+
EMAIL = "chad@spicycode.com"
|
10
|
+
HOMEPAGE = "http://spicycode.com"
|
11
|
+
SUMMARY = "An excellent replacement for the wheel..."
|
12
|
+
|
13
|
+
spec = Gem::Specification.new do |s|
|
14
|
+
s.name = GEM
|
15
|
+
s.version = GEM_VERSION
|
16
|
+
s.platform = Gem::Platform::RUBY
|
17
|
+
s.has_rdoc = true
|
18
|
+
s.extra_rdoc_files = ["README", "LICENSE"]
|
19
|
+
s.summary = SUMMARY
|
20
|
+
s.description = s.summary
|
21
|
+
s.author = AUTHOR
|
22
|
+
s.email = EMAIL
|
23
|
+
s.homepage = HOMEPAGE
|
24
|
+
|
25
|
+
# Uncomment this to add a dependency
|
26
|
+
s.add_dependency "mocha"
|
27
|
+
|
28
|
+
s.require_path = 'lib'
|
29
|
+
s.autorequire = GEM
|
30
|
+
s.files = %w(LICENSE README Rakefile) + Dir.glob("{lib,examples}/**/*")
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "Run all examples"
|
34
|
+
task :default do
|
35
|
+
examples = Dir["examples/**/*_example.rb"].map { |g| Dir.glob(g) }.flatten
|
36
|
+
examples.map! {|f| %Q(require "#{f}")}
|
37
|
+
command = "-e '#{examples.join("; ")}'"
|
38
|
+
ruby command
|
39
|
+
end
|
40
|
+
|
41
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
42
|
+
pkg.gem_spec = spec
|
43
|
+
end
|
44
|
+
|
45
|
+
desc "install the gem locally"
|
46
|
+
task :install => [:package] do
|
47
|
+
sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
|
48
|
+
end
|
49
|
+
|
50
|
+
desc "create a gemspec file"
|
51
|
+
task :make_spec do
|
52
|
+
File.open("#{GEM}.gemspec", "w") do |file|
|
53
|
+
file.puts spec.to_ruby
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
lib_path = File.expand_path(File.dirname(__FILE__) + "/../lib")
|
2
|
+
$LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
|
3
|
+
|
4
|
+
require 'micronaut'
|
5
|
+
|
6
|
+
|
7
|
+
module Micronaut
|
8
|
+
module Matchers
|
9
|
+
def fail
|
10
|
+
raise_error(::Micronaut::Exceptions::ExpectationNotMetError)
|
11
|
+
end
|
12
|
+
|
13
|
+
def fail_with(message)
|
14
|
+
raise_error(::Micronaut::Exceptions::ExpectationNotMetError, message)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
Micronaut::ExampleRunner.autorun
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../example_helper")
|
2
|
+
|
3
|
+
describe Micronaut::ExampleGroup do
|
4
|
+
class Foo; end
|
5
|
+
|
6
|
+
def scenario_1
|
7
|
+
example_group = Micronaut::ExampleGroup.new(Foo, "Scenario 1")
|
8
|
+
example_group.it("should do 1 thing") { 1 }
|
9
|
+
example_group.it("should do 2 thing") { 2 }
|
10
|
+
example_group.it("should do 3 thing") { 3 }
|
11
|
+
example_group
|
12
|
+
end
|
13
|
+
|
14
|
+
def scenario_2
|
15
|
+
example_group = Micronaut::ExampleGroup.new(Foo, "Scenario 2")
|
16
|
+
example_group.before { 'beforeeach1' }
|
17
|
+
example_group.before { 'beforeeach2' }
|
18
|
+
example_group.before(:all) { 'beforeall1' }
|
19
|
+
example_group.before(:all) { 'beforeall2' }
|
20
|
+
example_group
|
21
|
+
end
|
22
|
+
|
23
|
+
def scenario_3
|
24
|
+
example_group = Micronaut::ExampleGroup.new(Foo, "Scenario 3")
|
25
|
+
example_group.after { 'aftereach1' }
|
26
|
+
example_group.after { 'aftereach2' }
|
27
|
+
example_group.after(:all) { 'afterall1' }
|
28
|
+
example_group.after(:all) { 'afterall2' }
|
29
|
+
example_group
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should make the first parameter the name by calling to_s on it" do
|
33
|
+
scenario_1.name.should == 'Foo'
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should make the second parameter the description" do
|
37
|
+
scenario_1.description.should == 'Scenario 1'
|
38
|
+
end
|
39
|
+
|
40
|
+
it "scenario 1 should have 3 examples" do
|
41
|
+
scenario_1.should have(3).examples
|
42
|
+
end
|
43
|
+
|
44
|
+
it "scenario 1 should maintain the example order" do
|
45
|
+
example_group = scenario_1
|
46
|
+
example_group.examples[0].first.should == 'should do 1 thing'
|
47
|
+
example_group.examples[1].first.should == 'should do 2 thing'
|
48
|
+
example_group.examples[2].first.should == 'should do 3 thing'
|
49
|
+
end
|
50
|
+
|
51
|
+
it "scenario 1 should allow you to call it's examples" do
|
52
|
+
example_group = scenario_1
|
53
|
+
example_group.examples[0].last.call.should == 1
|
54
|
+
example_group.examples[1].last.call.should == 2
|
55
|
+
example_group.examples[2].last.call.should == 3
|
56
|
+
end
|
57
|
+
|
58
|
+
it "scenario 2 should have 2 before each parts" do
|
59
|
+
scenario_2.should have(2).before_each_parts
|
60
|
+
end
|
61
|
+
|
62
|
+
it "scenario 2 should have 2 before all parts" do
|
63
|
+
scenario_2.should have(2).before_all_parts
|
64
|
+
end
|
65
|
+
|
66
|
+
it "scenario 2 should maintain the before parts order" do
|
67
|
+
example_group = scenario_2
|
68
|
+
example_group.before_all_parts[0].call.should == 'beforeall1'
|
69
|
+
example_group.before_all_parts[1].call.should == 'beforeall2'
|
70
|
+
example_group.before_each_parts[0].call.should == 'beforeeach1'
|
71
|
+
example_group.before_each_parts[1].call.should == 'beforeeach2'
|
72
|
+
end
|
73
|
+
|
74
|
+
it "scenario 3 should have 2 after each parts" do
|
75
|
+
scenario_3.should have(2).after_each_parts
|
76
|
+
end
|
77
|
+
|
78
|
+
it "scenario 3 should have 2 after all parts" do
|
79
|
+
scenario_3.should have(2).after_all_parts
|
80
|
+
end
|
81
|
+
|
82
|
+
it "scenario 3 should maintain the after parts order" do
|
83
|
+
example_group = scenario_3
|
84
|
+
example_group.after_all_parts[0].call.should == 'afterall1'
|
85
|
+
example_group.after_all_parts[1].call.should == 'afterall2'
|
86
|
+
example_group.after_each_parts[0].call.should == 'aftereach1'
|
87
|
+
example_group.after_each_parts[1].call.should == 'aftereach2'
|
88
|
+
end
|
89
|
+
|
90
|
+
def scenario_4
|
91
|
+
example_group = Micronaut::ExampleGroup.new(Foo, "Scenario 4")
|
92
|
+
example_group
|
93
|
+
end
|
94
|
+
|
95
|
+
it "scenario 4 should run the before all blocks, before each blocks, the example, the after each blocks, and finally the after all blocks" do
|
96
|
+
example_group = scenario_4
|
97
|
+
example_group.before(:all) { 'before_all_1' }
|
98
|
+
example_group.before(:all) { 'before_all_2' }
|
99
|
+
example_group.before { "before_each_1"; @foo = 2 }
|
100
|
+
example_group.before { "before_each_2"; @foo += 1 }
|
101
|
+
example_group.before { "before_each_3"; @foo += 2 }
|
102
|
+
example_group.after { "after_each_1"; @foo = 3 }
|
103
|
+
example_group.after { "after_each_2"; 'final after each' }
|
104
|
+
example_group.after(:all) { 'after_all_1' }
|
105
|
+
example_group.after(:all) { 'after_all_2' }
|
106
|
+
|
107
|
+
example_group.it("prints out the value of the @foo variable") do
|
108
|
+
@foo.should == 5
|
109
|
+
end
|
110
|
+
example_group.it("other example") do
|
111
|
+
|
112
|
+
end
|
113
|
+
example_group.run
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../../example_helper")
|
2
|
+
require 'micronaut/expectations/differs/default'
|
3
|
+
|
4
|
+
module Micronaut
|
5
|
+
module Fixtures
|
6
|
+
class Animal
|
7
|
+
def initialize(name,species)
|
8
|
+
@name,@species = name,species
|
9
|
+
end
|
10
|
+
|
11
|
+
def inspect
|
12
|
+
<<-EOA
|
13
|
+
<Animal
|
14
|
+
name=#{@name},
|
15
|
+
species=#{@species}
|
16
|
+
>
|
17
|
+
EOA
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "Diff" do
|
24
|
+
|
25
|
+
before do
|
26
|
+
@differ = Micronaut::Expectations::Differs::Default.new(:unified)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should output unified diff of two strings" do
|
30
|
+
expected="foo\nbar\nzap\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nline\n"
|
31
|
+
actual="foo\nzap\nbar\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nanother\nline\n"
|
32
|
+
expected_diff= <<'EOD'
|
33
|
+
|
34
|
+
|
35
|
+
@@ -1,6 +1,6 @@
|
36
|
+
foo
|
37
|
+
-zap
|
38
|
+
bar
|
39
|
+
+zap
|
40
|
+
this
|
41
|
+
is
|
42
|
+
soo
|
43
|
+
@@ -9,6 +9,5 @@
|
44
|
+
equal
|
45
|
+
insert
|
46
|
+
a
|
47
|
+
-another
|
48
|
+
line
|
49
|
+
EOD
|
50
|
+
|
51
|
+
diff = @differ.diff_as_string(expected, actual)
|
52
|
+
diff.should eql(expected_diff)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should output unified diff message of two arrays" do
|
56
|
+
expected = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'charlie', :width, 'quite wide' ]
|
57
|
+
actual = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'tango' , :width, 'very wide' ]
|
58
|
+
|
59
|
+
expected_diff = <<'EOD'
|
60
|
+
|
61
|
+
|
62
|
+
@@ -5,7 +5,7 @@
|
63
|
+
:metasyntactic,
|
64
|
+
"variable",
|
65
|
+
:delta,
|
66
|
+
- "tango",
|
67
|
+
+ "charlie",
|
68
|
+
:width,
|
69
|
+
- "very wide"]
|
70
|
+
+ "quite wide"]
|
71
|
+
EOD
|
72
|
+
|
73
|
+
|
74
|
+
diff = @differ.diff_as_object(expected,actual)
|
75
|
+
diff.should == expected_diff
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should output unified diff message of two objects" do
|
79
|
+
expected = Micronaut::Fixtures::Animal.new "bob", "giraffe"
|
80
|
+
actual = Micronaut::Fixtures::Animal.new "bob", "tortoise"
|
81
|
+
|
82
|
+
expected_diff = <<'EOD'
|
83
|
+
|
84
|
+
@@ -1,5 +1,5 @@
|
85
|
+
<Animal
|
86
|
+
name=bob,
|
87
|
+
- species=tortoise
|
88
|
+
+ species=giraffe
|
89
|
+
>
|
90
|
+
EOD
|
91
|
+
|
92
|
+
diff = @differ.diff_as_object(expected,actual)
|
93
|
+
diff.should == expected_diff
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
describe "Diff in context format" do
|
100
|
+
before(:each) do
|
101
|
+
@differ = Micronaut::Expectations::Differs::Default.new(:context)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should output unified diff message of two objects" do
|
105
|
+
expected = Micronaut::Fixtures::Animal.new "bob", "giraffe"
|
106
|
+
actual = Micronaut::Fixtures::Animal.new "bob", "tortoise"
|
107
|
+
|
108
|
+
expected_diff = <<'EOD'
|
109
|
+
|
110
|
+
***************
|
111
|
+
*** 1,5 ****
|
112
|
+
<Animal
|
113
|
+
name=bob,
|
114
|
+
! species=tortoise
|
115
|
+
>
|
116
|
+
--- 1,5 ----
|
117
|
+
<Animal
|
118
|
+
name=bob,
|
119
|
+
! species=giraffe
|
120
|
+
>
|
121
|
+
EOD
|
122
|
+
|
123
|
+
diff = @differ.diff_as_object(expected,actual)
|
124
|
+
diff.should == expected_diff
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../../example_helper")
|
2
|
+
|
3
|
+
describe Object, "#should" do
|
4
|
+
|
5
|
+
before(:each) 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
|
+
|
21
|
+
lambda { @target.should @matcher }.should fail_with("the failure message")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should raise error if it receives false directly" do
|
25
|
+
lambda { @target.should false }.should raise_error(Micronaut::Expectations::InvalidMatcherError)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should raise error if it receives false (evaluated)" do
|
29
|
+
lambda { @target.should eql?("foo") }.should raise_error(Micronaut::Expectations::InvalidMatcherError)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should raise error if it receives true" do
|
33
|
+
lambda { @target.should true }.should raise_error(Micronaut::Expectations::InvalidMatcherError)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
describe Object, "#should_not" do
|
39
|
+
|
40
|
+
before(:each) do
|
41
|
+
@target = "target"
|
42
|
+
@matcher = mock("matcher")
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should accept and interact with a matcher" do
|
46
|
+
@matcher.expects(:matches?).with(@target).returns(false)
|
47
|
+
@matcher.stubs(:negative_failure_message)
|
48
|
+
|
49
|
+
@target.should_not @matcher
|
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 {
|
56
|
+
@target.should_not @matcher
|
57
|
+
}.should fail_with("the negative failure message")
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should raise error if it receives false directly" do
|
61
|
+
lambda {
|
62
|
+
@target.should_not false
|
63
|
+
}.should raise_error(Micronaut::Expectations::InvalidMatcherError)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should raise error if it receives false (evaluated)" do
|
67
|
+
lambda {
|
68
|
+
@target.should_not eql?("foo")
|
69
|
+
}.should raise_error(Micronaut::Expectations::InvalidMatcherError)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should raise error if it receives true" do
|
73
|
+
lambda {
|
74
|
+
@target.should_not true
|
75
|
+
}.should raise_error(Micronaut::Expectations::InvalidMatcherError)
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
|
2
|
+
|
3
|
+
describe Micronaut::Expectations, "#fail_with with no diff" do
|
4
|
+
before(:each) do
|
5
|
+
@old_differ = Micronaut::Expectations.differ
|
6
|
+
Micronaut::Expectations.differ = nil
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should handle just a message" do
|
10
|
+
lambda {
|
11
|
+
Micronaut::Expectations.fail_with "the message"
|
12
|
+
}.should fail_with("the message")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should handle an Array" do
|
16
|
+
lambda {
|
17
|
+
Micronaut::Expectations.fail_with ["the message","expected","actual"]
|
18
|
+
}.should fail_with("the message")
|
19
|
+
end
|
20
|
+
|
21
|
+
after(:each) do
|
22
|
+
Micronaut::Expectations.differ = @old_differ
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe Micronaut::Expectations, "#fail_with with diff" do
|
27
|
+
before(:each) do
|
28
|
+
@old_differ = Micronaut::Expectations.differ
|
29
|
+
@differ = mock("differ")
|
30
|
+
Micronaut::Expectations.differ = @differ
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should not call differ if no expected/actual" do
|
34
|
+
lambda {
|
35
|
+
Micronaut::Expectations.fail_with "the message"
|
36
|
+
}.should fail_with("the message")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should call differ if expected/actual are presented separately" do
|
40
|
+
@differ.expects(:diff_as_string).returns("diff")
|
41
|
+
lambda {
|
42
|
+
Micronaut::Expectations.fail_with "the message", "expected", "actual"
|
43
|
+
}.should fail_with("the message\nDiff:diff")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should call differ if expected/actual are not strings" do
|
47
|
+
@differ.expects(:diff_as_object).returns("diff")
|
48
|
+
lambda {
|
49
|
+
Micronaut::Expectations.fail_with "the message", :expected, :actual
|
50
|
+
}.should fail_with("the message\nDiff:diff")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should not call differ if expected or actual are procs" do
|
54
|
+
@differ.expects(:diff_as_string).never
|
55
|
+
@differ.expects(:diff_as_object).never
|
56
|
+
lambda {
|
57
|
+
Micronaut::Expectations.fail_with "the message", lambda {}, lambda {}
|
58
|
+
}.should fail_with("the message")
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should call differ if expected/actual are presented in an Array with message" do
|
62
|
+
@differ.expects(:diff_as_string).with("actual","expected").returns("diff")
|
63
|
+
lambda {
|
64
|
+
Micronaut::Expectations.fail_with(["the message", "expected", "actual"])
|
65
|
+
}.should fail_with(/the message\nDiff:diff/)
|
66
|
+
end
|
67
|
+
|
68
|
+
after(:each) do
|
69
|
+
Micronaut::Expectations.differ = @old_differ
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
|
2
|
+
|
3
|
+
module Micronaut
|
4
|
+
module Matchers
|
5
|
+
describe "wrap_expectation" do
|
6
|
+
|
7
|
+
def stub_matcher
|
8
|
+
@_stub_matcher ||= simple_matcher do
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def failing_matcher
|
13
|
+
@_failing_matcher ||= simple_matcher do
|
14
|
+
1.should == 2
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should return true if there is no error" do
|
19
|
+
wrap_expectation stub_matcher do
|
20
|
+
end.should be_true
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return false if there is an error" do
|
24
|
+
wrap_expectation failing_matcher do
|
25
|
+
raise "error"
|
26
|
+
end.should be_false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'autotest'
|
2
|
+
|
3
|
+
Autotest.add_hook :initialize do |at|
|
4
|
+
at.clear_mappings
|
5
|
+
# watch out: Ruby bug (1.8.6):
|
6
|
+
# %r(/) != /\//
|
7
|
+
at.add_mapping(%r%^examples/.*_example.rb$%) { |filename, _|
|
8
|
+
filename
|
9
|
+
}
|
10
|
+
at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
|
11
|
+
["examples/#{m[1]}_example.rb"]
|
12
|
+
}
|
13
|
+
at.add_mapping(%r%^examples/(examples_helper|shared/.*)\.rb$%) {
|
14
|
+
at.files_matching %r%^examples/.*_example\.rb$%
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
class MicronautCommandError < StandardError; end
|
19
|
+
|
20
|
+
class Autotest::Micronaut < Autotest
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
super
|
24
|
+
self.failed_results_re = /^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m
|
25
|
+
self.completed_re = /\n(?:\e\[\d*m)?\d* examples?/m
|
26
|
+
end
|
27
|
+
|
28
|
+
def consolidate_failures(failed)
|
29
|
+
filters = new_hash_of_arrays
|
30
|
+
failed.each do |spec, trace|
|
31
|
+
if trace =~ /\n(\.\/)?(.*example\.rb):[\d]+:\Z?/
|
32
|
+
filters[$2] << spec
|
33
|
+
end
|
34
|
+
end
|
35
|
+
return filters
|
36
|
+
end
|
37
|
+
|
38
|
+
def make_test_cmd(files_to_test)
|
39
|
+
return '' if files_to_test.empty?
|
40
|
+
return "#{ruby} -S #{files_to_test.keys.flatten.join(' ')}"
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|