spicycode-micronaut 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -0
- data/VERSION.yml +1 -1
- data/examples/example_helper.rb +2 -3
- data/examples/lib/micronaut/behaviour_example.rb +7 -2
- data/examples/lib/micronaut/formatters/base_formatter_example.rb +3 -7
- data/examples/lib/micronaut/formatters/progress_formatter_example.rb +1 -33
- data/lib/micronaut/behaviour.rb +3 -3
- data/lib/micronaut/example.rb +45 -11
- data/lib/micronaut/formatters/base_formatter.rb +13 -34
- data/lib/micronaut/formatters/base_text_formatter.rb +7 -29
- data/lib/micronaut/formatters/documentation_formatter.rb +26 -13
- data/lib/micronaut/formatters/progress_formatter.rb +11 -18
- data/lib/micronaut/world.rb +1 -1
- data/lib/micronaut.rb +0 -1
- metadata +5 -4
data/Rakefile
CHANGED
@@ -12,6 +12,8 @@ begin
|
|
12
12
|
s.authors = ["Chad Humphries"]
|
13
13
|
s.files = FileList["[A-Z]*", "{bin,lib,examples}/**/*"]
|
14
14
|
end
|
15
|
+
rescue => e
|
16
|
+
puts "Jeweler, or one of its dependencies blew right up. #{e}"
|
15
17
|
rescue LoadError
|
16
18
|
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
17
19
|
end
|
data/VERSION.yml
CHANGED
data/examples/example_helper.rb
CHANGED
@@ -8,9 +8,7 @@ def with_ruby(version)
|
|
8
8
|
yield if RUBY_PLATFORM =~ Regexp.compile("^#{version}")
|
9
9
|
end
|
10
10
|
|
11
|
-
with_ruby("1.8")
|
12
|
-
gem :mocha
|
13
|
-
end
|
11
|
+
with_ruby("1.8") { gem :mocha }
|
14
12
|
|
15
13
|
require File.expand_path(File.dirname(__FILE__) + "/resources/example_classes")
|
16
14
|
|
@@ -45,5 +43,6 @@ Micronaut.configure do |c|
|
|
45
43
|
c.mock_with :mocha
|
46
44
|
c.color_enabled = not_in_editor?
|
47
45
|
c.filter_run :focused => true
|
46
|
+
c.profile_examples = true
|
48
47
|
#c.formatter = :documentation
|
49
48
|
end
|
@@ -236,7 +236,7 @@ describe Micronaut::Behaviour do
|
|
236
236
|
|
237
237
|
end
|
238
238
|
|
239
|
-
|
239
|
+
pending "#run_examples" do
|
240
240
|
|
241
241
|
def stub_behaviour
|
242
242
|
stub_everything('behaviour', :metadata => { :behaviour => { :name => 'behaviour_name' }})
|
@@ -290,7 +290,12 @@ describe Micronaut::Behaviour do
|
|
290
290
|
|
291
291
|
|
292
292
|
it "should be able to access the before all ivars in the before_all_ivars hash" do
|
293
|
-
|
293
|
+
with_ruby('1.8') do
|
294
|
+
running_example.behaviour.before_all_ivars.should include('@before_all_top_level' => 'before_all_top_level')
|
295
|
+
end
|
296
|
+
with_ruby('1.9') do
|
297
|
+
running_example.behaviour.before_all_ivars.should include(:@before_all_top_level => 'before_all_top_level')
|
298
|
+
end
|
294
299
|
end
|
295
300
|
|
296
301
|
describe "but now I am nested" do
|
@@ -76,12 +76,8 @@ describe Micronaut::Formatters::BaseFormatter do
|
|
76
76
|
@formatter.should have_interface_for(:example_started).with(1).argument
|
77
77
|
end
|
78
78
|
|
79
|
-
it "should have
|
80
|
-
@formatter.should have_interface_for(:
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should have example_pending as an interface with two arguments" do
|
84
|
-
@formatter.should have_interface_for(:example_pending).with(2).arguments
|
79
|
+
it "should have example_finished as an interface with one argument" do
|
80
|
+
@formatter.should have_interface_for(:example_finished).with(1).arguments
|
85
81
|
end
|
86
82
|
|
87
83
|
it "should have start_dump as an interface with 1 arguments" do
|
@@ -122,4 +118,4 @@ describe Micronaut::Formatters::BaseFormatter do
|
|
122
118
|
|
123
119
|
end
|
124
120
|
|
125
|
-
end
|
121
|
+
end
|
@@ -21,41 +21,9 @@ describe Micronaut::Formatters::ProgressFormatter do
|
|
21
21
|
@output.string.should =~ /Finished in 3 seconds\n2 examples/i
|
22
22
|
end
|
23
23
|
|
24
|
-
it "should produce standard summary" do
|
25
|
-
@formatter.start_dump(3)
|
26
|
-
@formatter.example_pending(running_example, "message")
|
27
|
-
@output.rewind
|
28
|
-
@formatter.dump_summary
|
29
|
-
@output.string.should =~ /Finished in 3 seconds\n2 examples/i
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "when color is enabled" do
|
33
|
-
|
34
|
-
before do
|
35
|
-
@formatter.stubs(:trace?).returns(false)
|
36
|
-
@formatter.stubs(:color_enabled?).returns(true)
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should output a green dot for passing spec" do
|
40
|
-
@formatter.example_passed("spec")
|
41
|
-
@output.string.should == "\e[32m.\e[0m"
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should push red F for failure spec" do
|
45
|
-
@formatter.example_failed("spec", Micronaut::Expectations::ExpectationNotMetError.new)
|
46
|
-
@output.string.should == "\e[31mF\e[0m"
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should push magenta F for error spec" do
|
50
|
-
@formatter.example_failed("spec", RuntimeError.new)
|
51
|
-
@output.string.should == "\e[35mF\e[0m"
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
24
|
it "should push nothing on start" do
|
57
25
|
@formatter.start(4)
|
58
26
|
@output.string.should == ""
|
59
27
|
end
|
60
28
|
|
61
|
-
end
|
29
|
+
end
|
data/lib/micronaut/behaviour.rb
CHANGED
@@ -50,7 +50,7 @@ module Micronaut
|
|
50
50
|
def self.example(desc=nil, options={}, &block)
|
51
51
|
examples << Micronaut::Example.new(self, desc, options.update(:caller => caller[0]), block)
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def self.alias_example_to(new_alias, extra_options={})
|
55
55
|
new_alias = <<-END_RUBY
|
56
56
|
def self.#{new_alias}(desc=nil, options={}, &block)
|
@@ -62,7 +62,7 @@ module Micronaut
|
|
62
62
|
END_RUBY
|
63
63
|
module_eval(new_alias, __FILE__, __LINE__)
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
alias_example_to :it
|
67
67
|
alias_example_to :focused, :focused => true
|
68
68
|
alias_example_to :disabled, :disabled => true
|
@@ -196,7 +196,7 @@ module Micronaut
|
|
196
196
|
|
197
197
|
# Runs all examples, returning true only if all of them pass
|
198
198
|
def self.run_examples(behaviour_instance, reporter)
|
199
|
-
examples_to_run.map { |ex| ex.run(behaviour_instance
|
199
|
+
examples_to_run.map { |ex| ex.run(behaviour_instance) }.all?
|
200
200
|
end
|
201
201
|
|
202
202
|
def self.subclass(base_name, &body) # :nodoc:
|
data/lib/micronaut/example.rb
CHANGED
@@ -8,15 +8,40 @@ module Micronaut
|
|
8
8
|
@behaviour, @description, @options, @example_block = behaviour, desc, options, example_block
|
9
9
|
@metadata = @behaviour.metadata.dup
|
10
10
|
@metadata[:description] = description
|
11
|
+
@metadata[:execution_result] = {}
|
11
12
|
@metadata.update(options)
|
12
13
|
end
|
13
14
|
|
14
|
-
def
|
15
|
-
|
15
|
+
def record_results(results={})
|
16
|
+
@metadata[:execution_result].update(results)
|
17
|
+
end
|
18
|
+
|
19
|
+
def execution_result
|
20
|
+
@metadata[:execution_result]
|
16
21
|
end
|
17
22
|
|
18
|
-
def
|
19
|
-
|
23
|
+
def run_started
|
24
|
+
record_results :started_at => Time.now
|
25
|
+
Micronaut.configuration.formatter.example_started(self)
|
26
|
+
end
|
27
|
+
|
28
|
+
def run_passed
|
29
|
+
run_finished 'passed'
|
30
|
+
end
|
31
|
+
|
32
|
+
def run_pending(message='Not yet implemented')
|
33
|
+
run_finished 'pending', :pending_message => message
|
34
|
+
end
|
35
|
+
|
36
|
+
def run_failed(exception)
|
37
|
+
run_finished 'failed', :exception_encountered => exception
|
38
|
+
end
|
39
|
+
|
40
|
+
def run_finished(status, results={})
|
41
|
+
record_results results.update(:status => status)
|
42
|
+
finish_time = Time.now
|
43
|
+
record_results :finished_at => finish_time, :run_time => (finish_time - execution_result[:started_at])
|
44
|
+
Micronaut.configuration.formatter.example_finished(self)
|
20
45
|
end
|
21
46
|
|
22
47
|
def run_before_each
|
@@ -34,16 +59,17 @@ module Micronaut
|
|
34
59
|
def run_example
|
35
60
|
if example_block
|
36
61
|
@behaviour_instance.instance_eval(&example_block)
|
37
|
-
|
62
|
+
run_passed
|
38
63
|
else
|
39
|
-
|
64
|
+
run_pending
|
40
65
|
end
|
41
66
|
end
|
42
67
|
|
43
|
-
def run(behaviour_instance
|
44
|
-
@behaviour_instance
|
68
|
+
def run(behaviour_instance)
|
69
|
+
@behaviour_instance = behaviour_instance
|
45
70
|
@behaviour_instance.running_example = self
|
46
|
-
|
71
|
+
|
72
|
+
run_started
|
47
73
|
|
48
74
|
all_systems_nominal = true
|
49
75
|
exception_encountered = nil
|
@@ -64,11 +90,19 @@ module Micronaut
|
|
64
90
|
ensure
|
65
91
|
@behaviour_instance.running_example = nil
|
66
92
|
end
|
67
|
-
|
68
|
-
|
93
|
+
|
94
|
+
run_failed(exception_encountered) if exception_encountered
|
69
95
|
|
70
96
|
all_systems_nominal
|
71
97
|
end
|
98
|
+
|
99
|
+
def inspect
|
100
|
+
"#{@metadata[:behaviour][:name]} - #{@metadata[:description]}"
|
101
|
+
end
|
102
|
+
|
103
|
+
def to_s
|
104
|
+
inspect
|
105
|
+
end
|
72
106
|
|
73
107
|
end
|
74
108
|
|
@@ -2,11 +2,12 @@ module Micronaut
|
|
2
2
|
module Formatters
|
3
3
|
|
4
4
|
class BaseFormatter
|
5
|
-
attr_accessor :behaviour
|
6
|
-
attr_reader :example_count, :duration
|
5
|
+
attr_accessor :behaviour
|
6
|
+
attr_reader :example_count, :duration, :examples
|
7
7
|
|
8
8
|
def initialize
|
9
|
-
@
|
9
|
+
@example_count = 0
|
10
|
+
@examples = []
|
10
11
|
@behaviour = nil
|
11
12
|
end
|
12
13
|
|
@@ -35,16 +36,12 @@ module Micronaut
|
|
35
36
|
configuration.color_enabled?
|
36
37
|
end
|
37
38
|
|
38
|
-
def example_profiling_info
|
39
|
-
@example_profiling_info ||= []
|
40
|
-
end
|
41
|
-
|
42
39
|
def pending_examples
|
43
|
-
@pending_examples ||=
|
40
|
+
@pending_examples ||= ::Micronaut.world.find(examples, :execution_result => { :status => 'pending' })
|
44
41
|
end
|
45
42
|
|
46
43
|
def failed_examples
|
47
|
-
@failed_examples ||=
|
44
|
+
@failed_examples ||= ::Micronaut.world.find(examples, :execution_result => { :status => 'failed' })
|
48
45
|
end
|
49
46
|
|
50
47
|
# This method is invoked before any examples are run, right after
|
@@ -57,6 +54,13 @@ module Micronaut
|
|
57
54
|
@example_count = example_count
|
58
55
|
end
|
59
56
|
|
57
|
+
def example_started(example)
|
58
|
+
end
|
59
|
+
|
60
|
+
def example_finished(example)
|
61
|
+
examples << example
|
62
|
+
end
|
63
|
+
|
60
64
|
# This method is invoked at the beginning of the execution of each behaviour.
|
61
65
|
# +behaviour+ is the behaviour.
|
62
66
|
#
|
@@ -65,31 +69,6 @@ module Micronaut
|
|
65
69
|
@behaviour = behaviour
|
66
70
|
end
|
67
71
|
|
68
|
-
# This method is invoked when an +example+ starts.
|
69
|
-
def example_started(example)
|
70
|
-
end
|
71
|
-
|
72
|
-
# This method is invoked when an +example+ passes.
|
73
|
-
def example_passed(example)
|
74
|
-
end
|
75
|
-
|
76
|
-
# This method is invoked when an +example+ fails, i.e. an exception occurred
|
77
|
-
# inside it (such as a failed should or other exception). +counter+ is the
|
78
|
-
# sequence number of the failure (starting at 1) and +failure+ is the associated
|
79
|
-
# exception.
|
80
|
-
def example_failed(example, exception)
|
81
|
-
@total_example_failed += 1
|
82
|
-
end
|
83
|
-
|
84
|
-
# This method is invoked when an example is not yet implemented (i.e. has not
|
85
|
-
# been provided a block), or when an ExamplePendingError is raised.
|
86
|
-
# +message+ is the message from the ExamplePendingError, if it exists, or the
|
87
|
-
# default value of "Not Yet Implemented"
|
88
|
-
# +pending_caller+ is the file and line number of the spec which
|
89
|
-
# has called the pending method
|
90
|
-
def example_pending(example, message)
|
91
|
-
end
|
92
|
-
|
93
72
|
# This method is invoked after all of the examples have executed. The next method
|
94
73
|
# to be invoked after this one is #dump_failure (once for each failed example),
|
95
74
|
def start_dump(duration)
|
@@ -3,33 +3,11 @@ module Micronaut
|
|
3
3
|
module Formatters
|
4
4
|
|
5
5
|
class BaseTextFormatter < BaseFormatter
|
6
|
-
|
7
|
-
def example_passed(example)
|
8
|
-
super
|
9
|
-
# Why && @start_time
|
10
|
-
if profile_examples? && @start_time
|
11
|
-
example_profiling_info << [example, Time.now - @start_time]
|
12
|
-
end
|
13
|
-
end
|
14
6
|
|
15
|
-
def example_started(example)
|
16
|
-
super
|
17
|
-
@start_time = Time.now
|
18
|
-
end
|
19
|
-
|
20
|
-
def example_pending(example, message)
|
21
|
-
pending_examples << [example, message]
|
22
|
-
end
|
23
|
-
|
24
|
-
def example_failed(example, exception)
|
25
|
-
super
|
26
|
-
failed_examples << [example, exception]
|
27
|
-
end
|
28
|
-
|
29
7
|
def dump_failures
|
30
8
|
output.puts
|
31
|
-
failed_examples.each_with_index do |
|
32
|
-
|
9
|
+
failed_examples.each_with_index do |failed_example, index|
|
10
|
+
exception = failed_example.execution_result[:exception_encountered]
|
33
11
|
padding = ' '
|
34
12
|
|
35
13
|
output.puts "#{index.next}) #{failed_example}"
|
@@ -77,11 +55,11 @@ module Micronaut
|
|
77
55
|
|
78
56
|
# Don't print out profiled info if there are failures, it just clutters the output
|
79
57
|
if profile_examples? && failure_count == 0
|
80
|
-
sorted_examples =
|
58
|
+
sorted_examples = examples.sort_by { |example| example.execution_result[:run_time] }.reverse.first(10)
|
81
59
|
output.puts "\nTop #{sorted_examples.size} slowest examples:\n"
|
82
|
-
sorted_examples.
|
83
|
-
output.puts " (#{sprintf("%.7f",
|
84
|
-
output.puts grey(" # #{
|
60
|
+
sorted_examples.each do |example|
|
61
|
+
output.puts " (#{sprintf("%.7f", example.execution_result[:run_time])} seconds) #{example}"
|
62
|
+
output.puts grey(" # #{example.metadata[:caller]}")
|
85
63
|
end
|
86
64
|
end
|
87
65
|
|
@@ -154,4 +132,4 @@ module Micronaut
|
|
154
132
|
|
155
133
|
end
|
156
134
|
|
157
|
-
end
|
135
|
+
end
|
@@ -25,9 +25,27 @@ module Micronaut
|
|
25
25
|
@previous_nested_behaviours = described_behaviour_chain
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def output_for(example)
|
29
|
+
case example.execution_result[:status]
|
30
|
+
when 'failed'
|
31
|
+
failure_output(example, example.execution_result[:exception_encountered])
|
32
|
+
when 'pending'
|
33
|
+
pending_output(example, example.execution_result[:pending_message])
|
34
|
+
when 'passed'
|
35
|
+
passed_output(example)
|
36
|
+
else
|
37
|
+
red(example.execution_result[:status])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def example_finished(example)
|
29
42
|
super
|
30
|
-
|
43
|
+
output.puts output_for(example)
|
44
|
+
output.flush
|
45
|
+
end
|
46
|
+
|
47
|
+
def failure_output(example, exception)
|
48
|
+
expectation_not_met = exception.is_a?(::Micronaut::Expectations::ExpectationNotMetError)
|
31
49
|
|
32
50
|
message = if expectation_not_met
|
33
51
|
"#{current_indentation}#{example.description} (FAILED)"
|
@@ -35,20 +53,15 @@ module Micronaut
|
|
35
53
|
"#{current_indentation}#{example.description} (ERROR)"
|
36
54
|
end
|
37
55
|
|
38
|
-
|
39
|
-
output.flush
|
56
|
+
expectation_not_met ? red(message) : magenta(message)
|
40
57
|
end
|
41
58
|
|
42
|
-
def
|
43
|
-
|
44
|
-
output.puts green("#{current_indentation}#{example.description}")
|
45
|
-
output.flush
|
59
|
+
def passed_output(example)
|
60
|
+
green("#{current_indentation}#{example.description}")
|
46
61
|
end
|
47
62
|
|
48
|
-
def
|
49
|
-
|
50
|
-
output.puts yellow("#{current_indentation}#{example.description} (PENDING: #{message})")
|
51
|
-
output.flush
|
63
|
+
def pending_output(example, message)
|
64
|
+
yellow("#{current_indentation}#{example.description} (PENDING: #{message})")
|
52
65
|
end
|
53
66
|
|
54
67
|
def current_indentation
|
@@ -62,4 +75,4 @@ module Micronaut
|
|
62
75
|
end
|
63
76
|
|
64
77
|
end
|
65
|
-
end
|
78
|
+
end
|
@@ -3,22 +3,19 @@ module Micronaut
|
|
3
3
|
|
4
4
|
class ProgressFormatter < BaseTextFormatter
|
5
5
|
|
6
|
-
def
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def output_for(example)
|
7
|
+
case example.execution_result[:status]
|
8
|
+
when 'failed' then colorise('F', example.execution_result[:exception_encountered])
|
9
|
+
when 'pending' then yellow('*')
|
10
|
+
when 'passed' then green('.')
|
11
|
+
else
|
12
|
+
red(example.execution_result[:status])
|
13
|
+
end
|
10
14
|
end
|
11
15
|
|
12
|
-
def
|
16
|
+
def example_finished(example)
|
13
17
|
super
|
14
|
-
output.print
|
15
|
-
output.flush
|
16
|
-
end
|
17
|
-
|
18
|
-
def example_pending(example, message)
|
19
|
-
super
|
20
|
-
output.print yellow('*')
|
21
|
-
output.flush
|
18
|
+
output.print output_for(example)
|
22
19
|
end
|
23
20
|
|
24
21
|
def start_dump(duration)
|
@@ -27,11 +24,7 @@ module Micronaut
|
|
27
24
|
output.flush
|
28
25
|
end
|
29
26
|
|
30
|
-
def method_missing(sym, *args)
|
31
|
-
# ignore
|
32
|
-
end
|
33
|
-
|
34
27
|
end
|
35
28
|
|
36
29
|
end
|
37
|
-
end
|
30
|
+
end
|
data/lib/micronaut/world.rb
CHANGED
@@ -18,7 +18,7 @@ module Micronaut
|
|
18
18
|
if filter
|
19
19
|
@behaviours_to_run = filter_behaviours
|
20
20
|
if @behaviours_to_run.size == 0 && Micronaut.configuration.run_all_when_everything_filtered?
|
21
|
-
puts "No
|
21
|
+
puts "No examples were matched by #{filter.inspect}, running all"
|
22
22
|
# reset the behaviour list to all behaviours, and add back all examples
|
23
23
|
@behaviours_to_run = @behaviours
|
24
24
|
@behaviours.each { |b| b.examples_to_run.replace(b.examples) }
|
data/lib/micronaut.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spicycode-micronaut
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chad Humphries
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-03-10 00:00:00 -07:00
|
13
13
|
default_executable: micronaut
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -19,8 +19,9 @@ executables:
|
|
19
19
|
- micronaut
|
20
20
|
extensions: []
|
21
21
|
|
22
|
-
extra_rdoc_files:
|
23
|
-
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.markdown
|
24
|
+
- LICENSE
|
24
25
|
files:
|
25
26
|
- History.txt
|
26
27
|
- LICENSE
|