eetee 0.0.4 → 0.0.5
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/Gemfile +1 -0
- data/examples/eventmachine/em.rb +26 -0
- data/lib/eetee/assertion_wrapper.rb +5 -3
- data/lib/eetee/context.rb +20 -3
- data/lib/eetee/reporter.rb +1 -1
- data/lib/eetee/reporters/console.rb +1 -1
- data/lib/eetee/runner.rb +2 -2
- data/lib/eetee/version.rb +1 -1
- data/lib/eetee.rb +2 -2
- data/lib/guard/eetee.rb +43 -3
- data/specs/unit/context_spec.rb +110 -18
- metadata +4 -4
data/Gemfile
CHANGED
data/examples/eventmachine/em.rb
CHANGED
@@ -2,11 +2,37 @@ require 'rubygems'
|
|
2
2
|
require 'bundler/setup'
|
3
3
|
|
4
4
|
require 'eetee'
|
5
|
+
require 'eetee/ext/mocha'
|
5
6
|
require 'eetee/ext/em'
|
6
7
|
|
8
|
+
class EMHandler < EM::Connection
|
9
|
+
def initialize(arg)
|
10
|
+
@arg = arg
|
11
|
+
end
|
12
|
+
|
13
|
+
def receive_data(data)
|
14
|
+
@arg.toto()
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
|
7
20
|
describe 'context' do
|
8
21
|
before do
|
9
22
|
@fib = Fiber.current
|
23
|
+
@port = 23456 + rand(100)
|
24
|
+
@srv = EM::start_server('127.0.0.1', @port, EMHandler, mock('Trash'))
|
25
|
+
end
|
26
|
+
|
27
|
+
should 'wait packet (and fails)' do
|
28
|
+
|
29
|
+
socket = EM::connect('127.0.0.1', @port)
|
30
|
+
|
31
|
+
EM::add_timer(0.1) do
|
32
|
+
socket.send_data("data")
|
33
|
+
end
|
34
|
+
|
35
|
+
wait(1)
|
10
36
|
end
|
11
37
|
|
12
38
|
should 'run in a fiber inside EventMachine' do
|
@@ -35,8 +35,8 @@ module EEtee
|
|
35
35
|
|
36
36
|
def close?(target, error_margin)
|
37
37
|
invert_helper(
|
38
|
-
"expected #{target} += #{error_margin}, got #{
|
39
|
-
"expected to be outside of #{target} += #{error_margin}, got #{
|
38
|
+
"expected #{target} += #{error_margin}, got #{@object}",
|
39
|
+
"expected to be outside of #{target} += #{error_margin}, got #{@object}"
|
40
40
|
) do
|
41
41
|
(target-error_margin .. target+error_margin).should.include?(@object)
|
42
42
|
end
|
@@ -65,7 +65,9 @@ module EEtee
|
|
65
65
|
ret = @object.__send__(name, *args, &block)
|
66
66
|
|
67
67
|
if !!ret == !!@invert
|
68
|
-
if args.
|
68
|
+
if ((name == :'==') || (name == :'!=')) && (!@object.nil? || !args[0].nil?)
|
69
|
+
msg = "\n#{@object}\n#{name}\n#{args[0]}\n=> #{ret} (size: #{@object.size} / #{args[0].size})"
|
70
|
+
elsif args.empty?
|
69
71
|
msg = "#{@object.inspect}.#{name}() => #{ret}"
|
70
72
|
else
|
71
73
|
msg = "#{@object.inspect}.#{name}(#{args}) => #{ret}"
|
data/lib/eetee/context.rb
CHANGED
@@ -1,17 +1,28 @@
|
|
1
1
|
module EEtee
|
2
2
|
|
3
|
+
NOT_CLONEABLE_TYPES = [Fixnum, NilClass, TrueClass, FalseClass].freeze
|
4
|
+
|
3
5
|
module SharedContextMethods
|
4
6
|
def before(&block)
|
5
7
|
@before ||= []
|
6
8
|
@before << block
|
7
9
|
end
|
8
10
|
|
11
|
+
def after(&block)
|
12
|
+
@after ||= []
|
13
|
+
@after << block
|
14
|
+
end
|
15
|
+
|
9
16
|
def describe(description, &block)
|
10
17
|
vars = {}
|
11
18
|
|
12
19
|
instance_variables.reject{|name| name.to_s.start_with?('@_') }.each do |name|
|
13
20
|
value = instance_variable_get(name)
|
14
|
-
|
21
|
+
if NOT_CLONEABLE_TYPES.include?(value.class)
|
22
|
+
vars[name] = value
|
23
|
+
else
|
24
|
+
vars[name] = value.clone
|
25
|
+
end
|
15
26
|
end
|
16
27
|
|
17
28
|
Context.new(description, @_level + 1, @_reporter, vars, @_focus_mode, &block)
|
@@ -23,8 +34,12 @@ module EEtee
|
|
23
34
|
|
24
35
|
def it(label, opts = {}, &block)
|
25
36
|
if !@_focus_mode || opts[:focus]
|
26
|
-
|
27
|
-
|
37
|
+
begin
|
38
|
+
(@before || []).each{|b| instance_eval(&b) }
|
39
|
+
Test.new(label, @_reporter, &block)
|
40
|
+
ensure
|
41
|
+
(@after || []).each{|b| instance_eval(&b) }
|
42
|
+
end
|
28
43
|
end
|
29
44
|
end
|
30
45
|
end
|
@@ -37,6 +52,8 @@ module EEtee
|
|
37
52
|
def description; @_description; end
|
38
53
|
def level; @_level; end
|
39
54
|
|
55
|
+
alias_method :context_description, :description
|
56
|
+
|
40
57
|
def initialize(description, level, reporter, vars = {}, focus_mode = false, &block)
|
41
58
|
vars.each do |name, value|
|
42
59
|
instance_variable_set(name, value)
|
data/lib/eetee/reporter.rb
CHANGED
data/lib/eetee/runner.rb
CHANGED
@@ -6,7 +6,7 @@ module EEtee
|
|
6
6
|
extend Forwardable
|
7
7
|
attr_reader :focus_mode
|
8
8
|
|
9
|
-
def_delegators :@reporter, :failures, :errors, :assertions, :test_count
|
9
|
+
def_delegators :@reporter, :failures, :errors, :empty, :assertions, :test_count
|
10
10
|
|
11
11
|
def initialize
|
12
12
|
@reporter = EEtee.default_reporter_class.new
|
@@ -34,7 +34,7 @@ module EEtee
|
|
34
34
|
paths.each do |path|
|
35
35
|
if File.exist?(path)
|
36
36
|
data = File.read(path)
|
37
|
-
if data =~ /^\s+(should|it).*?,\s
|
37
|
+
if data =~ /^\s+(should|it).*?,\s+:?focus.* do$/
|
38
38
|
puts "Focus enabled."
|
39
39
|
@focus_mode = true
|
40
40
|
else
|
data/lib/eetee/version.rb
CHANGED
data/lib/eetee.rb
CHANGED
data/lib/guard/eetee.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
require 'guard'
|
2
2
|
require 'guard/guard'
|
3
3
|
|
4
|
-
gem 'guard', '~> 1.5.3'
|
5
|
-
|
6
4
|
module Guard
|
7
|
-
class
|
5
|
+
class Eetee < Guard
|
6
|
+
ERROR_COLOR = [255, 56, 84].freeze
|
7
|
+
EMPTY_COLOR = [0, 159, 193].freeze
|
8
|
+
FAILURES_COLOR = [226, 117, 0].freeze
|
9
|
+
SUCCESS_COLOR = [0, 219, 5].freeze
|
10
|
+
FADE_DURATION = 200
|
11
|
+
|
8
12
|
|
9
13
|
def self.template(*)
|
10
14
|
File.read(
|
@@ -16,6 +20,8 @@ module Guard
|
|
16
20
|
# @param [Array<Guard::Watcher>] watchers the Guard file watchers
|
17
21
|
# @param [Hash] options the custom Guard options
|
18
22
|
def initialize(watchers = [], options = {})
|
23
|
+
@reporter_class = options.delete(:reporter)
|
24
|
+
@with_blink1 = options.delete(:blink1)
|
19
25
|
super
|
20
26
|
end
|
21
27
|
|
@@ -28,6 +34,12 @@ module Guard
|
|
28
34
|
# Called when `stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
|
29
35
|
# @raise [:task_has_failed] when stop has failed
|
30
36
|
def stop
|
37
|
+
if @with_blink1
|
38
|
+
@blink1 = Blink1.new
|
39
|
+
@blink1.open()
|
40
|
+
@blink1.set_rgb(0,0,0)
|
41
|
+
@blink1.close()
|
42
|
+
end
|
31
43
|
puts "Guard::EEtee stopped."
|
32
44
|
end
|
33
45
|
|
@@ -50,6 +62,12 @@ module Guard
|
|
50
62
|
def run_on_changes(paths)
|
51
63
|
pid = Kernel.fork do
|
52
64
|
require 'eetee'
|
65
|
+
|
66
|
+
if @reporter_class
|
67
|
+
EEtee.default_reporter_class = EEtee::Reporters.const_get(@reporter_class)
|
68
|
+
end
|
69
|
+
|
70
|
+
|
53
71
|
runner = EEtee::Runner.new
|
54
72
|
runner.run_files(paths)
|
55
73
|
runner.report_results()
|
@@ -59,6 +77,28 @@ module Guard
|
|
59
77
|
|
60
78
|
focus_mode = runner.focus_mode
|
61
79
|
|
80
|
+
if @with_blink1
|
81
|
+
blink1 = Blink1.new
|
82
|
+
blink1.open()
|
83
|
+
|
84
|
+
if runner.errors.size > 0
|
85
|
+
blink1.fade_to_rgb(FADE_DURATION, *ERROR_COLOR)
|
86
|
+
|
87
|
+
elsif runner.failures.size > 0
|
88
|
+
blink1.fade_to_rgb(FADE_DURATION, *FAILURES_COLOR)
|
89
|
+
|
90
|
+
elsif runner.empty.size > 0
|
91
|
+
blink1.fade_to_rgb(FADE_DURATION, *EMPTY_COLOR)
|
92
|
+
|
93
|
+
else
|
94
|
+
blink1.fade_to_rgb(FADE_DURATION, *SUCCESS_COLOR)
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
blink1.close()
|
99
|
+
end
|
100
|
+
|
101
|
+
|
62
102
|
if failures > 0
|
63
103
|
Notifier.notify("Specs: #{failures} Failures (#{tests} tests) #{focus_mode ? '(focus)' : ''}",
|
64
104
|
:image => :failed
|
data/specs/unit/context_spec.rb
CHANGED
@@ -9,31 +9,118 @@ describe 'Context' do
|
|
9
9
|
|
10
10
|
should 'run block in context' do
|
11
11
|
a = nil
|
12
|
+
test_th_id = nil
|
13
|
+
|
14
|
+
@reporter.stubs(:increment_assertions)
|
15
|
+
|
16
|
+
th_id = Thread.current.object_id
|
17
|
+
|
12
18
|
Thread.new do
|
13
19
|
EEtee::Context.new("a context", 0, @reporter, :@a => 34) do
|
20
|
+
test_th_id = Thread.current.object_id
|
14
21
|
a = @a
|
15
22
|
end
|
16
23
|
end.join
|
24
|
+
|
25
|
+
th_id.should.not == test_th_id
|
17
26
|
a.should == 34
|
18
27
|
end
|
19
28
|
|
20
29
|
should 'run before block in same context' do
|
21
30
|
a = nil
|
22
31
|
Thread.new do
|
23
|
-
|
24
|
-
|
25
|
-
|
32
|
+
EEtee::Context.new("a context", 0, @reporter, :@a => 234) do
|
33
|
+
before{ a = @a }
|
34
|
+
should("do nothing"){} # just to run the before block
|
35
|
+
end
|
26
36
|
end.join
|
27
37
|
a.should == 234
|
28
38
|
end
|
29
39
|
|
40
|
+
should 'allow tests to use the context description' do
|
41
|
+
a = nil
|
42
|
+
Thread.new do
|
43
|
+
EEtee::Context.new("a context", 0, @reporter, :@a => 234) do
|
44
|
+
should("do nothing"){ a = context_description() }
|
45
|
+
end
|
46
|
+
end.join
|
47
|
+
a.should == "a context"
|
48
|
+
end
|
49
|
+
|
50
|
+
should 'allow tests to use the nested context description' do
|
51
|
+
a = nil
|
52
|
+
Thread.new do
|
53
|
+
EEtee::Context.new("a context", 0, @reporter, :@a => 234) do
|
54
|
+
describe("sub context") do
|
55
|
+
should("do nothing"){ a = context_description() }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end.join
|
59
|
+
a.should == "sub context"
|
60
|
+
end
|
61
|
+
|
62
|
+
should 'run after block in same context' do
|
63
|
+
a = nil
|
64
|
+
Thread.new do
|
65
|
+
EEtee::Context.new("a context", 0, @reporter, :@a => 234) do
|
66
|
+
after{ a = @a }
|
67
|
+
should("do nothing"){} # just to run the before block
|
68
|
+
end
|
69
|
+
end.join
|
70
|
+
a.should == 234
|
71
|
+
end
|
72
|
+
|
73
|
+
|
30
74
|
should 'run the before blocks before every test' do
|
31
75
|
n = 0
|
32
76
|
Thread.new do
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
77
|
+
EEtee::Context.new("a context", 0, @reporter) do
|
78
|
+
before{ n = 1 }
|
79
|
+
should("test 1"){ n += 2 }
|
80
|
+
should("test 2"){ n += 2 }
|
81
|
+
end
|
82
|
+
end.join
|
83
|
+
n.should == 3
|
84
|
+
end
|
85
|
+
|
86
|
+
should 'run the after blocks after every test' do
|
87
|
+
n = 0
|
88
|
+
Thread.new do
|
89
|
+
EEtee::Context.new("a context", 0, @reporter) do
|
90
|
+
after{ n = 1 }
|
91
|
+
should("test 1"){ n += 2 }
|
92
|
+
should("test 2"){ n += 2 }
|
93
|
+
end
|
94
|
+
end.join
|
95
|
+
n.should == 1
|
96
|
+
end
|
97
|
+
|
98
|
+
should 'run the after blocks after when an error occured in test' do
|
99
|
+
n = 0
|
100
|
+
Thread.new do
|
101
|
+
begin
|
102
|
+
EEtee::Context.new("a context", 0, @reporter) do
|
103
|
+
after{ n = 1 }
|
104
|
+
should("test 1"){ raise "toto" }
|
105
|
+
end
|
106
|
+
rescue
|
107
|
+
end
|
108
|
+
end.join
|
109
|
+
n.should == 1
|
110
|
+
end
|
111
|
+
|
112
|
+
should 'only run the rigth before blocks' do
|
113
|
+
n = 0
|
114
|
+
Thread.new do
|
115
|
+
EEtee::Context.new("a context", 0, @reporter) do
|
116
|
+
before{ n = 1 }
|
117
|
+
|
118
|
+
describe("sub context") do
|
119
|
+
before { n = 10 }
|
120
|
+
end
|
121
|
+
|
122
|
+
should("test 1"){ n += 2 }
|
123
|
+
end
|
37
124
|
end.join
|
38
125
|
n.should == 3
|
39
126
|
end
|
@@ -41,8 +128,9 @@ describe 'Context' do
|
|
41
128
|
should 'copy instance variables in nested contexts' do
|
42
129
|
a = b = nil
|
43
130
|
Thread.new do
|
44
|
-
|
45
|
-
|
131
|
+
EEtee::Context.new("a context", 0, @reporter, :@a => 98, :@b => "string") do
|
132
|
+
describe("nested context"){ a = @a; b = @b }
|
133
|
+
end
|
46
134
|
end.join
|
47
135
|
a.should == 98
|
48
136
|
b.should == "string"
|
@@ -53,8 +141,9 @@ describe 'Context' do
|
|
53
141
|
EEtee::Test.expects(:new).with("should test something", @reporter)
|
54
142
|
Thread.new do
|
55
143
|
begin
|
56
|
-
|
57
|
-
|
144
|
+
EEtee::Context.new("a context", 0, @reporter, :@a => 98, :@b => "string") do
|
145
|
+
should("test something"){ 1.should == 1 }
|
146
|
+
end
|
58
147
|
rescue Exception => ex
|
59
148
|
err = ex
|
60
149
|
end
|
@@ -69,9 +158,10 @@ describe 'Context' do
|
|
69
158
|
|
70
159
|
Thread.new do
|
71
160
|
begin
|
72
|
-
|
73
|
-
|
74
|
-
|
161
|
+
EEtee::Context.new("a context", 0, @reporter, {:@a => 98, :@b => "string"}, true) do
|
162
|
+
should("test something", :focus => true){ n = 1 }
|
163
|
+
should("test something"){ n = 2 }
|
164
|
+
end
|
75
165
|
rescue Exception => ex
|
76
166
|
err = ex
|
77
167
|
end
|
@@ -87,10 +177,12 @@ describe 'Context' do
|
|
87
177
|
|
88
178
|
Thread.new do
|
89
179
|
begin
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
180
|
+
EEtee::Context.new("a context", 0, @reporter, {:@a => 98, :@b => "string"}, true) do
|
181
|
+
describe("nested") do
|
182
|
+
should("test something", :focus => true){ n = 1 }
|
183
|
+
should("test something"){ n = 2 }
|
184
|
+
end
|
185
|
+
end
|
94
186
|
rescue Exception => ex
|
95
187
|
err = ex
|
96
188
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eetee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-03-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: term-ansicolor
|
@@ -88,7 +88,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
88
88
|
version: '0'
|
89
89
|
segments:
|
90
90
|
- 0
|
91
|
-
hash:
|
91
|
+
hash: 1275779178498727194
|
92
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
93
|
none: false
|
94
94
|
requirements:
|
@@ -97,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
97
|
version: '0'
|
98
98
|
segments:
|
99
99
|
- 0
|
100
|
-
hash:
|
100
|
+
hash: 1275779178498727194
|
101
101
|
requirements: []
|
102
102
|
rubyforge_project:
|
103
103
|
rubygems_version: 1.8.23
|