lookout 2.1.2 → 2.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/lib/lookout.rb +0 -1
  2. data/lib/lookout/equalities.rb +13 -0
  3. data/lib/lookout/equalities/array.rb +22 -0
  4. data/lib/lookout/equalities/boolean.rb +9 -0
  5. data/lib/lookout/equalities/hash.rb +25 -0
  6. data/lib/lookout/equalities/include.rb +9 -0
  7. data/lib/lookout/equalities/object.rb +24 -0
  8. data/lib/lookout/equalities/output.rb +19 -0
  9. data/lib/lookout/equalities/standarderror.rb +26 -0
  10. data/lib/lookout/equalities/string.rb +19 -0
  11. data/lib/lookout/equalities/warning.rb +16 -0
  12. data/lib/lookout/equality.rb +1 -158
  13. data/lib/lookout/expectations.rb +17 -22
  14. data/lib/lookout/mock.rb +5 -3
  15. data/lib/lookout/result.rb +1 -11
  16. data/lib/lookout/results.rb +3 -38
  17. data/lib/lookout/results/error.rb +3 -3
  18. data/lib/lookout/results/failure.rb +2 -2
  19. data/lib/lookout/results/failures/behavior.rb +2 -1
  20. data/lib/lookout/results/failures/state.rb +2 -1
  21. data/lib/lookout/results/fulfilled.rb +2 -6
  22. data/lib/lookout/results/instance.rb +17 -0
  23. data/lib/lookout/results/unsuccessful.rb +37 -0
  24. data/lib/lookout/runners/console.rb +16 -6
  25. data/lib/lookout/stub.rb +5 -3
  26. data/lib/lookout/ui/console.rb +27 -17
  27. data/lib/lookout/ui/silent.rb +1 -4
  28. data/lib/lookout/version.rb +1 -1
  29. data/test/unit/lookout/expectations.rb +47 -31
  30. data/test/unit/lookout/expectations/behavior.rb +20 -20
  31. data/test/unit/lookout/expectations/state.rb +15 -15
  32. data/test/unit/lookout/results.rb +0 -26
  33. data/test/unit/lookout/results/error.rb +0 -3
  34. data/test/unit/lookout/results/failures/behavior.rb +0 -3
  35. data/test/unit/lookout/results/failures/state.rb +0 -3
  36. data/test/unit/lookout/results/fulfilled.rb +0 -3
  37. data/test/unit/lookout/results/unsuccessful.rb +24 -0
  38. data/test/unit/lookout/stub/methods.rb +19 -0
  39. data/test/unit/lookout/ui/formatters/exception/backtrace.rb +3 -4
  40. metadata +31 -20
  41. data/lib/lookout/benchmark.rb +0 -11
  42. data/test/unit/lookout/mock.rb +0 -4
  43. data/test/unit/lookout/stub.rb +0 -4
@@ -2,7 +2,6 @@
2
2
 
3
3
  module Lookout
4
4
  autoload :Aphonic, 'lookout/aphonic'
5
- autoload :Benchmark, 'lookout/benchmark'
6
5
  autoload :Diff, 'lookout/diff'
7
6
  autoload :Equality, 'lookout/equality'
8
7
  autoload :Expectation, 'lookout/expectation'
@@ -0,0 +1,13 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Lookout::Equalities
4
+ require 'lookout/equalities/object'
5
+ require 'lookout/equalities/array'
6
+ require 'lookout/equalities/boolean'
7
+ require 'lookout/equalities/hash'
8
+ require 'lookout/equalities/include'
9
+ require 'lookout/equalities/output'
10
+ require 'lookout/equalities/standarderror'
11
+ require 'lookout/equalities/string'
12
+ require 'lookout/equalities/warning'
13
+ end
@@ -0,0 +1,22 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ class Lookout::Equalities::Array < Lookout::Equalities::Object
4
+ Lookout::Equality.register self, Array
5
+
6
+ def equal?(expected, actual)
7
+ return false unless Array === actual and expected.size == actual.size
8
+ expected.each_with_index do |v, i|
9
+ return false unless Lookout::Equality.equal? v, actual[i]
10
+ end
11
+ true
12
+ end
13
+
14
+ def diff(expected, actual)
15
+ return if expected.size == 1 or not Array === actual
16
+ Lookout::Diff::Formats::Unified.
17
+ new(Lookout::Diff::Groups.
18
+ new(Lookout::Diff::Operations.
19
+ new(Lookout::Diff::Algorithms::Difflib.
20
+ new(actual, expected)))).to_a.join("\n")
21
+ end
22
+ end
@@ -0,0 +1,9 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ class Lookout::Equalities::Boolean < Lookout::Equalities::Object
4
+ Lookout::Equality.register self, TrueClass, FalseClass
5
+
6
+ def equal?(expected, actual)
7
+ expected == !!actual
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ class Lookout::Equalities::Hash < Lookout::Equalities::Object
4
+ Lookout::Equality.register self, Hash
5
+
6
+ def equal?(expected, actual)
7
+ return false unless Hash === actual and expected.size == actual.size
8
+ expected.all?{ |k, v| Lookout::Equality.equal? v, actual[k] }
9
+ end
10
+
11
+ def diff(expected, actual)
12
+ return if expected.size == 1 or not Hash === actual
13
+ Lookout::Diff::Formats::Hash.
14
+ new(Lookout::Diff::Operations.
15
+ new(Lookout::Diff::Algorithms::Difflib.
16
+ new(array(actual), array(expected)))).to_a.join("\n")
17
+ end
18
+
19
+ private
20
+
21
+ def array(hash)
22
+ hash.to_a.sort_by{ |k, v| k }.map{ |k, v| '%p => %p' % [k, v] }
23
+ end
24
+ end
25
+
@@ -0,0 +1,9 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ class Lookout::Equalities::Includes < Lookout::Equalities::Object
4
+ Lookout::Equality.register self, Module, Range, Regexp
5
+
6
+ def equal?(expected, actual)
7
+ expected === actual or expected == actual
8
+ end
9
+ end
@@ -0,0 +1,24 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ class Lookout::Equalities::Object
4
+ Lookout::Equality.register self, Object
5
+
6
+ def equal?(expected, actual)
7
+ expected == actual
8
+ end
9
+
10
+ def message(expected, actual)
11
+ format = format(expected, actual)
12
+ return format unless diff = diff(expected, actual)
13
+ (diff.include?("\n") ? "%s\n%s" : '%s: %s') % [format, diff]
14
+ end
15
+
16
+ def diff(expected, actual)
17
+ end
18
+
19
+ private
20
+
21
+ def format(expected, actual)
22
+ '%p≠%p' % [actual, expected]
23
+ end
24
+ end
@@ -0,0 +1,19 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ class Lookout::Equalities::Output < Lookout::Equalities::Object
4
+ Lookout::Equality.register self, Lookout::Output
5
+
6
+ def equal?(expected, _actual)
7
+ expected.expected == expected.actual
8
+ end
9
+
10
+ def diff(expected, _actual)
11
+ Lookout::Equality.diff(expected.expected, expected.actual)
12
+ end
13
+
14
+ private
15
+
16
+ def format(expected, _actual)
17
+ '%p≠%p' % [Lookout::Output.new(expected.actual), expected]
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ class Lookout::Equalities::StandardError < Lookout::Equalities::Object
4
+ Lookout::Equality.register self, ::StandardError
5
+
6
+ def equal?(expected, actual)
7
+ expected.equal?(actual) or
8
+ ((actual.respond_to? :message rescue false) and
9
+ ((Regexp === expected.message and expected.message === actual.message) or
10
+ expected.message == actual.message))
11
+ end
12
+
13
+ def diff(expected, actual)
14
+ return super unless String === expected.message and
15
+ StandardError === actual and (actual.respond_to? :message rescue false)
16
+ Lookout::Equality.diff(expected.message, actual.message)
17
+ end
18
+
19
+ private
20
+
21
+ def format(expected, actual)
22
+ Regexp === expected.message ?
23
+ '%p≠#<%s: %p>' % [actual, expected.class, expected.message] :
24
+ super
25
+ end
26
+ end
@@ -0,0 +1,19 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ class Lookout::Equalities::String < Lookout::Equalities::Object
4
+ Lookout::Equality.register self, String
5
+
6
+ def diff(expected, actual)
7
+ return unless String === actual
8
+ (expected.include? "\n" or actual.include? "\n") ?
9
+ Lookout::Diff::Formats::Unified.
10
+ new(Lookout::Diff::Groups.
11
+ new(Lookout::Diff::Operations.
12
+ new(Lookout::Diff::Algorithms::Difflib.
13
+ new(actual.split("\n"),
14
+ expected.split("\n"))))).to_a.join("\n") :
15
+ Lookout::Diff::Formats::Inline.
16
+ new(Lookout::Diff::Operations.
17
+ new(Lookout::Diff::Algorithms::Difflib.new(actual, expected))).to_s
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ class Lookout::Equalities::Warning < Lookout::Equalities::String
4
+ Lookout::Equality.register self, Lookout::Warning
5
+
6
+ def equal?(expected, actual)
7
+ expected == actual.chomp or
8
+ actual =~ /\A.*?:\d+: warning: #{Regexp.escape(expected)}\Z/u
9
+ end
10
+
11
+ private
12
+
13
+ def format(expected, actual)
14
+ '%p≠%p' % [Lookout::Warning.new(actual), expected]
15
+ end
16
+ end
@@ -31,163 +31,6 @@ module Lookout::Equality
31
31
  @equalities ||= {}
32
32
  end
33
33
  end
34
- end
35
-
36
- class Lookout::Equality::Object
37
- Lookout::Equality.register self, Object
38
-
39
- def equal?(expected, actual)
40
- expected == actual
41
- end
42
-
43
- def message(expected, actual)
44
- format = format(expected, actual)
45
- return format unless diff = diff(expected, actual)
46
- (diff.include?("\n") ? "%s\n%s" : '%s: %s') % [format, diff]
47
- end
48
-
49
- def diff(expected, actual)
50
- end
51
-
52
- private
53
-
54
- def format(expected, actual)
55
- '%p≠%p' % [actual, expected]
56
- end
57
- end
58
-
59
- class Lookout::Equality::Includes < Lookout::Equality::Object
60
- Lookout::Equality.register self, Module, Range, Regexp
61
-
62
- def equal?(expected, actual)
63
- expected === actual or expected == actual
64
- end
65
- end
66
-
67
- class Lookout::Equality::Boolean < Lookout::Equality::Object
68
- Lookout::Equality.register self, TrueClass, FalseClass
69
-
70
- def equal?(expected, actual)
71
- expected == !!actual
72
- end
73
- end
74
-
75
- class Lookout::Equality::String < Lookout::Equality::Object
76
- Lookout::Equality.register self, String
77
-
78
- def diff(expected, actual)
79
- return unless String === actual
80
- (expected.include? "\n" or actual.include? "\n") ?
81
- Lookout::Diff::Formats::Unified.
82
- new(Lookout::Diff::Groups.
83
- new(Lookout::Diff::Operations.
84
- new(Lookout::Diff::Algorithms::Difflib.
85
- new(actual.split("\n"),
86
- expected.split("\n"))))).to_a.join("\n") :
87
- Lookout::Diff::Formats::Inline.
88
- new(Lookout::Diff::Operations.
89
- new(Lookout::Diff::Algorithms::Difflib.new(actual, expected))).to_s
90
- end
91
- end
92
-
93
- class Lookout::Equality::Array < Lookout::Equality::Object
94
- Lookout::Equality.register self, Array
95
-
96
- def equal?(expected, actual)
97
- return false unless Array === actual and expected.size == actual.size
98
- expected.each_with_index do |v, i|
99
- return false unless Lookout::Equality.equal? v, actual[i]
100
- end
101
- true
102
- end
103
-
104
- def diff(expected, actual)
105
- return if expected.size == 1 or not Array === actual
106
- Lookout::Diff::Formats::Unified.
107
- new(Lookout::Diff::Groups.
108
- new(Lookout::Diff::Operations.
109
- new(Lookout::Diff::Algorithms::Difflib.
110
- new(actual, expected)))).to_a.join("\n")
111
- end
112
- end
113
-
114
- class Lookout::Equality::Hash < Lookout::Equality::Object
115
- Lookout::Equality.register self, Hash
116
34
 
117
- def equal?(expected, actual)
118
- return false unless Hash === actual and expected.size == actual.size
119
- expected.all?{ |k, v| Lookout::Equality.equal? v, actual[k] }
120
- end
121
-
122
- def diff(expected, actual)
123
- return if expected.size == 1 or not Hash === actual
124
- Lookout::Diff::Formats::Hash.
125
- new(Lookout::Diff::Operations.
126
- new(Lookout::Diff::Algorithms::Difflib.
127
- new(array(actual), array(expected)))).to_a.join("\n")
128
- end
129
-
130
- private
131
-
132
- def array(hash)
133
- hash.to_a.sort_by{ |k, v| k }.map{ |k, v| '%p => %p' % [k, v] }
134
- end
135
- end
136
-
137
- class Lookout::Equality::StandardError < Lookout::Equality::Object
138
- Lookout::Equality.register self, ::StandardError
139
-
140
- def equal?(expected, actual)
141
- expected.equal?(actual) or
142
- ((actual.respond_to? :message rescue false) and
143
- ((Regexp === expected.message and expected.message === actual.message) or
144
- expected.message == actual.message))
145
- end
146
-
147
- def diff(expected, actual)
148
- return super unless String === expected.message and
149
- StandardError === actual and (actual.respond_to? :message rescue false)
150
- Lookout::Equality.diff(expected.message, actual.message)
151
- end
152
-
153
- private
154
-
155
- def format(expected, actual)
156
- Regexp === expected.message ?
157
- '%p≠#<%s: %p>' % [actual, expected.class, expected.message] :
158
- super
159
- end
160
- end
161
-
162
- class Lookout::Equality::Output < Lookout::Equality::Object
163
- Lookout::Equality.register self, Lookout::Output
164
-
165
- def equal?(expected, _actual)
166
- expected.expected == expected.actual
167
- end
168
-
169
- def diff(expected, _actual)
170
- Lookout::Equality.diff(expected.expected, expected.actual)
171
- end
172
-
173
- private
174
-
175
- def format(expected, _actual)
176
- '%p≠%p' % [Lookout::Output.new(expected.actual), expected]
177
- end
178
- end
179
-
180
- class Lookout::Equality::Warning < Lookout::Equality::String
181
- Lookout::Equality.register self, Lookout::Warning
182
-
183
- def equal?(expected, actual)
184
- expected == actual.chomp or
185
- actual =~ /\A.*?:\d+: warning: #{Regexp.escape(expected)}\Z/u
186
- end
187
-
188
- private
189
-
190
- def format(expected, actual)
191
- '%p≠%p' % [Lookout::Warning.new(actual), expected]
192
- end
35
+ require 'lookout/equalities'
193
36
  end
@@ -4,10 +4,9 @@ class Lookout::Expectations
4
4
  autoload :Behavior, 'lookout/expectations/behavior'
5
5
  autoload :State, 'lookout/expectations/state'
6
6
 
7
- include Enumerable
8
-
9
- def initialize
10
- @expectations = []
7
+ def initialize(results = Lookout::Results::Unsuccessful.new, line = nil)
8
+ @results, @line = results, line
9
+ @previous = nil
11
10
  end
12
11
 
13
12
  def mock
@@ -40,27 +39,23 @@ class Lookout::Expectations
40
39
 
41
40
  def expect(expected, &block)
42
41
  file, line = /\A(.*):(\d+)(?::in .*)?\z/.match(caller.first)[1..2]
43
- @expectations << Lookout::Expectation.on(expected, file, line, &block)
44
- expected
45
- end
46
-
47
- def evaluate(ui = Lookout::UI::Console.new, results = Lookout::Results.new)
48
- ui.start
49
- ui.summarize results, Lookout::Benchmark.time{
50
- each(ENV['LINE'] ? ENV['LINE'].to_i : nil) do |expectation|
51
- results << expectation.evaluate.tap{ |result| ui.report result }
42
+ expectation = Lookout::Expectation.on(expected, file, line, &block)
43
+ if @line
44
+ if @previous and @previous.line <= @line and expectation.line > @line
45
+ @results << @previous.evaluate
46
+ @previous = nil
47
+ else
48
+ @previous = expectation
52
49
  end
53
- }
54
- results
50
+ else
51
+ @results << expectation.evaluate
52
+ end
53
+ self
55
54
  end
56
55
 
57
- def each(line = nil)
58
- return enum_for(:each, line) unless block_given?
59
- (line ?
60
- Array(@expectations.reverse.find{ |e| e.line <= line }) :
61
- @expectations).each do |expectation|
62
- yield expectation
63
- end
56
+ # TODO: It would be great if this method wasn’t necessary.
57
+ def flush
58
+ @results << @previous.evaluate if @previous
64
59
  self
65
60
  end
66
61
  end
@@ -10,9 +10,11 @@ module Lookout::Mock
10
10
  class << self
11
11
  def methods
12
12
  methods = Methods.new
13
- yield methods
14
- ensure
15
- methods.undefine if methods
13
+ begin
14
+ yield methods
15
+ ensure
16
+ methods.undefine
17
+ end
16
18
  end
17
19
  end
18
20
  end
@@ -1,16 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- class Lookout::Result
4
- class << self
5
- def is(is)
6
- [:error, :failure, :fulfilled].each do |type|
7
- define_method :"#{type}?" do
8
- type == is
9
- end
10
- end
11
- end
12
- end
13
-
3
+ module Lookout::Result
14
4
  def initialize(file, line)
15
5
  @file, @line = file, line
16
6
  end
@@ -1,46 +1,11 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- class Lookout::Results
3
+ module Lookout::Results
4
4
  autoload :Error, 'lookout/results/error'
5
5
  autoload :Failure, 'lookout/results/failure'
6
6
  autoload :Failures, 'lookout/results/failures'
7
7
  autoload :Fulfilled, 'lookout/results/fulfilled'
8
8
 
9
- include Enumerable
10
-
11
- def initialize
12
- @results = []
13
- end
14
-
15
- def <<(result)
16
- @results << result
17
- self
18
- end
19
-
20
- def each
21
- @results.each do |result|
22
- yield result
23
- end
24
- self
25
- end
26
-
27
- def succeeded?
28
- all?{ |result| result.fulfilled? }
29
- end
30
-
31
- def size
32
- @results.size
33
- end
34
-
35
- def fulfillments
36
- select{ |result| result.fulfilled? }
37
- end
38
-
39
- def errors
40
- select{ |result| result.error? }
41
- end
42
-
43
- def failures
44
- select{ |result| result.failure? }
45
- end
9
+ autoload :Instance, 'lookout/results/instance'
10
+ autoload :Unsuccessful, 'lookout/results/unsuccessful'
46
11
  end
@@ -1,9 +1,9 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- class Lookout::Results::Error < Lookout::Result
4
- autoload :Exception, 'lookout/results/error/exception'
3
+ class Lookout::Results::Error
4
+ include Lookout::Result
5
5
 
6
- is :error
6
+ autoload :Exception, 'lookout/results/error/exception'
7
7
 
8
8
  def initialize(file, line, message, exception)
9
9
  super file, line
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- class Lookout::Results::Failure < Lookout::Result
4
- is :failure
3
+ module Lookout::Results::Failure
4
+ include Lookout::Result
5
5
 
6
6
  def initialize(file, line, message)
7
7
  super file, line
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- class Lookout::Results::Failures::Behavior < Lookout::Results::Failure
3
+ class Lookout::Results::Failures::Behavior
4
+ include Lookout::Results::Failure
4
5
  end
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- class Lookout::Results::Failures::State < Lookout::Results::Failure
3
+ class Lookout::Results::Failures::State
4
+ include Lookout::Results::Failure
4
5
  end
@@ -1,9 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- class Lookout::Results::Fulfilled < Lookout::Result
4
- is :fulfilled
5
-
6
- def initialize(file, line)
7
- super file, line
8
- end
3
+ class Lookout::Results::Fulfilled
4
+ include Lookout::Result
9
5
  end
@@ -0,0 +1,17 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Lookout::Results::Instance
4
+ def initialize
5
+ @listeners = []
6
+ end
7
+
8
+ def on_new(&block)
9
+ @listeners << block
10
+ end
11
+
12
+ def <<(result)
13
+ @listeners.each do |listener|
14
+ listener.call result
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,37 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ class Lookout::Results::Unsuccessful
4
+ include Lookout::Results::Instance
5
+
6
+ include Enumerable
7
+
8
+ def initialize
9
+ super
10
+ @unsuccessful = []
11
+ end
12
+
13
+ def <<(result)
14
+ @unsuccessful << result unless Lookout::Results::Fulfilled === result
15
+ super
16
+ self
17
+ end
18
+
19
+ def each
20
+ @unsuccessful.each do |result|
21
+ yield result
22
+ end
23
+ self
24
+ end
25
+
26
+ def succeeded?
27
+ @unsuccessful.empty?
28
+ end
29
+
30
+ def errors
31
+ select{ |result| Lookout::Results::Error === result }
32
+ end
33
+
34
+ def failures
35
+ select{ |result| Lookout::Results::Failure === result }
36
+ end
37
+ end
@@ -1,22 +1,32 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  class Lookout::Runners::Console
4
- def initialize(expectations = Lookout::Expectations.new)
5
- @expectations = expectations
6
- @run = true
4
+ def initialize(results = Lookout::Results::Unsuccessful.new,
5
+ expectations = Lookout::Expectations.new(results,
6
+ ENV['LINE'] && ENV['LINE'].to_i),
7
+ ui = Lookout::UI::Console.new(results))
8
+ @results, @expectations, @ui = results, expectations, ui
9
+ @ui.start
7
10
  end
8
11
 
9
12
  def install
10
13
  at_exit do
11
- exit 1 unless @run and @expectations.evaluate.succeeded?
14
+ next if $!
15
+ @expectations.flush
16
+ @ui.summarize
17
+ exit 1 unless @results.succeeded?
12
18
  end
13
19
  self
14
20
  end
15
21
 
16
22
  def expectations_eval(&block)
17
23
  @expectations.instance_eval(&block)
18
- rescue
19
- @run = false
24
+ rescue Interrupt, NoMemoryError, SignalException, SystemExit
20
25
  raise
26
+ rescue Exception => e
27
+ raise unless location = Array(e.backtrace).first
28
+ file, line = /\A(.*):(\d+)(?::in .*)?\z/.match(location)[1..2]
29
+ raise unless file and line
30
+ @results << Lookout::Results::Error.new(file, line, nil, e)
21
31
  end
22
32
  end
@@ -8,9 +8,11 @@ module Lookout::Stub
8
8
  class << self
9
9
  def methods
10
10
  methods = Methods.new
11
- yield methods
12
- ensure
13
- methods.undefine if methods
11
+ begin
12
+ yield methods
13
+ ensure
14
+ methods.undefine
15
+ end
14
16
  end
15
17
  end
16
18
  end
@@ -1,32 +1,42 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- class Lookout::UI::Console < Lookout::UI::Silent
4
- def initialize(io = $stdout)
5
- @io = io
3
+ class Lookout::UI::Console
4
+ def initialize(results, io = $stdout)
5
+ @results, @io = results, io
6
+ @count = 0
7
+ results.on_new do
8
+ @count += 1
9
+ end
10
+ end
11
+
12
+ def start
13
+ @start = Time.now.to_f
6
14
  end
7
15
 
8
- def summarize(results, time)
9
- return if results.succeeded?
10
- summarize_total results, time
11
- summarize_group results, :errors
12
- summarize_group results, :failures
16
+ def summarize
17
+ return if @results.succeeded?
18
+ summarize_total
19
+ summarize_group :errors
20
+ summarize_group :failures
13
21
  @io.flush
14
22
  end
15
23
 
16
24
  private
17
25
 
18
- def summarize_total(results, time)
26
+ def summarize_total
19
27
  @io.printf "Ran %d expectations in %.3f seconds: %s\n",
20
- results.size,
21
- time,
22
- [:errors, :failures, :fulfillments].inject([]){ |result, type|
23
- next result unless (size = results.send(type).size) > 0
24
- result << '%d %s' % [size, type]
25
- }.join(', ')
28
+ @count,
29
+ Time.now.to_f - @start,
30
+ [['errors', @results.errors.size],
31
+ ['failures', @results.failures.size]].tap{ |types|
32
+ types << ['fulfillments', @count - types.reduce(0){ |sum, pair| sum + pair[1] }]
33
+ }.select{ |type, size| size > 0 }.
34
+ map{ |type, size| '%d %s' % [size, type] }.
35
+ join(', ')
26
36
  end
27
37
 
28
- def summarize_group(results, type)
29
- group = results.send(type)
38
+ def summarize_group(type)
39
+ group = @results.send(type)
30
40
  return if group.empty?
31
41
  @io.puts '', type.to_s.upcase, ''
32
42
  group.each do |item|
@@ -4,9 +4,6 @@ class Lookout::UI::Silent
4
4
  def start
5
5
  end
6
6
 
7
- def report(result)
8
- end
9
-
10
- def summarize(results, time)
7
+ def summarize
11
8
  end
12
9
  end
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module Lookout
4
- Version = '2.1.2'
4
+ Version = '2.1.3'
5
5
  end
@@ -2,57 +2,73 @@
2
2
 
3
3
  Expectations do
4
4
  expect true do
5
- expectations = Lookout::Expectations.new
6
- expectations.evaluate(Lookout::UI::Silent.new).succeeded?
5
+ Lookout::Results::Unsuccessful.new.tap{ |results|
6
+ Lookout::Expectations.new(results)
7
+ }.succeeded?
7
8
  end
8
9
 
9
10
  expect false do
10
- expectations = Lookout::Expectations.new
11
- expectations.expect(1){ 2 }
12
- expectations.evaluate(Lookout::UI::Silent.new).succeeded?
11
+ Lookout::Results::Unsuccessful.new.tap{ |results|
12
+ Lookout::Expectations.new(results).expect(1){ 2 }
13
+ }.succeeded?
13
14
  end
14
15
 
15
16
  expect 3 do
16
- expectations = Lookout::Expectations.new
17
- expectations.expect(1){ 2 }
18
- expectations.expect(1){ 2 }
19
- expectations.expect(1){ 2 }
20
- expectations.count
17
+ Lookout::Results::Unsuccessful.new.tap{ |results|
18
+ Lookout::Expectations.new(results).
19
+ expect(1){ 2 }.
20
+ expect(1){ 2 }.
21
+ expect(1){ 2 }
22
+ }.count
21
23
  end
22
24
 
23
25
  expect 1 do
24
- expectations = Lookout::Expectations.new
25
- expectations.expect(1){ 2 }
26
- expectations.expect(1){ 2 }
27
- expectations.each(__LINE__ - 1).count
26
+ Lookout::Results::Unsuccessful.new.tap{ |results|
27
+ expectations = Lookout::Expectations.new(results, __LINE__ + 1)
28
+ expectations.expect(1){ 2 }
29
+ expectations.expect(1){ 2 }
30
+ }.count
28
31
  end
29
32
 
30
- expect __LINE__ + 2 do
31
- expectations = Lookout::Expectations.new
32
- expectations.expect(1){ 2 }
33
- expectations.first.line
33
+ expect 1 do
34
+ Lookout::Results::Unsuccessful.new.tap{ |results|
35
+ expectations = Lookout::Expectations.new(results, __LINE__ + 1)
36
+ expectations.expect(1){ 2 }
37
+ expectations.expect(1){ 2 }
38
+ expectations.flush
39
+ }.count
40
+ end
41
+
42
+ expect 1 do
43
+ Lookout::Results::Unsuccessful.new.tap{ |results|
44
+ expectations = Lookout::Expectations.new(results, __LINE__ + 2)
45
+ expectations.expect(1){ 2 }
46
+ expectations.expect(1){ 2 }
47
+ expectations.flush
48
+ }.count
34
49
  end
35
50
 
36
51
  expect __LINE__ + 2 do
37
- expectations = Lookout::Expectations.new
38
- expectations.expect(1){ raise }
39
- expectations.first.line
52
+ Lookout::Results::Unsuccessful.new.tap{ |results|
53
+ Lookout::Expectations.new(results).expect(1){ 2 }
54
+ }.first.line
40
55
  end
41
56
 
42
- expect __FILE__ do
43
- expectations = Lookout::Expectations.new
44
- expectations.expect(1){ 2 }
45
- expectations.first.file
57
+ expect __LINE__ + 2 do
58
+ Lookout::Results::Unsuccessful.new.tap{ |results|
59
+ Lookout::Expectations.new(results).expect(1){ raise }
60
+ }.first.line
46
61
  end
47
62
 
48
63
  expect __FILE__ do
49
- expectations = Lookout::Expectations.new
50
- expectations.expect(1){ raise }
51
- expectations.first.file
64
+ Lookout::Results::Unsuccessful.new.tap{ |results|
65
+ Lookout::Expectations.new(results).expect(1){ 2 }
66
+ }.first.file
52
67
  end
53
68
 
54
- expect Object.new do |o|
55
- expectations = Lookout::Expectations.new
56
- expectations.evaluate(Lookout::UI::Silent.new, o)
69
+ expect __FILE__ do
70
+ Lookout::Results::Unsuccessful.new.tap{ |results|
71
+ Lookout::Expectations.new(results).expect(1){ raise }
72
+ }.first.file
57
73
  end
58
74
  end
@@ -2,34 +2,34 @@
2
2
 
3
3
  Expectations do
4
4
  expect [Lookout::Results::Failures::Behavior] do
5
- expectations = Lookout::Expectations.new
6
- expectations.expect Object.new.to.receive.dial('2125551212').twice do |phone|
7
- phone.dial('2125551212')
8
- end
9
- expectations.evaluate(Lookout::UI::Silent.new).entries
5
+ Lookout::Results::Unsuccessful.new.tap{ |results|
6
+ Lookout::Expectations.new(results).expect Object.new.to.receive.dial('2125551212').twice do |phone|
7
+ phone.dial('2125551212')
8
+ end
9
+ }.entries
10
10
  end
11
11
 
12
12
  expect [Lookout::Results::Failures::Behavior] do
13
- expectations = Lookout::Expectations.new
14
- expectations.expect Object.new.to.receive.dial('2125551212').twice do |phone|
15
- phone.dial('2125551212')
16
- phone.dial('2125551212')
17
- phone.dial('2125551212')
18
- end
19
- expectations.evaluate(Lookout::UI::Silent.new).entries
13
+ Lookout::Results::Unsuccessful.new.tap{ |results|
14
+ Lookout::Expectations.new(results).expect Object.new.to.receive.dial('2125551212').twice do |phone|
15
+ phone.dial('2125551212')
16
+ phone.dial('2125551212')
17
+ phone.dial('2125551212')
18
+ end
19
+ }.entries
20
20
  end
21
21
 
22
22
  expect [Lookout::Results::Failures::Behavior] do
23
- expectations = Lookout::Expectations.new
24
- expectations.expect(Object.new.to.receive.deal){ }
25
- expectations.evaluate(Lookout::UI::Silent.new).entries
23
+ Lookout::Results::Unsuccessful.new.tap{ |results|
24
+ Lookout::Expectations.new(results).expect(Object.new.to.receive.deal)
25
+ }.entries
26
26
  end
27
27
 
28
28
  expect [Lookout::Results::Error] do
29
- expectations = Lookout::Expectations.new
30
- expectations.expect(Object.new.to.receive.foo) do
31
- raise StandardError
32
- end
33
- expectations.evaluate(Lookout::UI::Silent.new).entries
29
+ Lookout::Results::Unsuccessful.new.tap{ |results|
30
+ Lookout::Expectations.new(results).expect(Object.new.to.receive.foo) do
31
+ raise StandardError
32
+ end
33
+ }.entries
34
34
  end
35
35
  end
@@ -2,28 +2,28 @@
2
2
 
3
3
  Expectations do
4
4
  expect [Lookout::Results::Failures::State] do
5
- expectations = Lookout::Expectations.new
6
- expectations.expect(2){ 3 }
7
- expectations.evaluate(Lookout::UI::Silent.new).entries
5
+ Lookout::Results::Unsuccessful.new.tap{ |results|
6
+ Lookout::Expectations.new(results).expect(2){ 3 }
7
+ }.entries
8
8
  end
9
9
 
10
10
  expect [Lookout::Results::Error] do
11
- expectations = Lookout::Expectations.new
12
- expectations.expect(2){ stub(Object.new).two{ 2 }.twos }
13
- expectations.evaluate(Lookout::UI::Silent.new).entries
11
+ Lookout::Results::Unsuccessful.new.tap{ |results|
12
+ Lookout::Expectations.new(results).expect(2){ stub(Object.new).two{ 2 }.twos }
13
+ }.entries
14
14
  end
15
15
 
16
16
  expect [Lookout::Results::Error] do
17
- expectations = Lookout::Expectations.new
18
- expectations.expect(1) do
19
- Object.new.tap{ |o| o.expects.give_me_three(3){ 1 } }.give_me_three(stub).threes
20
- end
21
- expectations.evaluate(Lookout::UI::Silent.new).entries
17
+ Lookout::Results::Unsuccessful.new.tap{ |results|
18
+ Lookout::Expectations.new(results).expect 1 do
19
+ Object.new.tap{ |o| o.expects.give_me_three(3){ 1 } }.give_me_three(stub).threes
20
+ end
21
+ }.entries
22
22
  end
23
23
 
24
- expect [Lookout::Results::Fulfilled] do
25
- expectations = Lookout::Expectations.new
26
- expectations.expect(NoMethodError){ Object.no_method }
27
- expectations.evaluate(Lookout::UI::Silent.new).entries
24
+ expect [] do
25
+ Lookout::Results::Unsuccessful.new.tap{ |results|
26
+ Lookout::Expectations.new(results).expect(NoMethodError){ Object.no_method }
27
+ }.entries
28
28
  end
29
29
  end
@@ -1,30 +1,4 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  Expectations do
4
- expect 1 do
5
- results = Lookout::Results.new
6
- results << Lookout::Results::Fulfilled.new(nil, 0)
7
- results.fulfillments.size
8
- end
9
-
10
- expect 0 do
11
- results = Lookout::Results.new
12
- results << Lookout::Results::Fulfilled.new(nil, 0)
13
- results.errors.size
14
- end
15
-
16
- expect Lookout::Results.new.not.to.have.succeeded? do |results|
17
- results << Lookout::Results::Failures::State.new(nil, 0, nil)
18
- results << Lookout::Results::Fulfilled.new(nil, 0)
19
- end
20
-
21
- expect Lookout::Results.new.not.to.have.succeeded? do |results|
22
- results << Lookout::Results::Failures::Behavior.new(nil, 0, nil)
23
- results << Lookout::Results::Fulfilled.new(nil, 0)
24
- end
25
-
26
- expect Lookout::Results.new.to.have.succeeded? do |results|
27
- results << Lookout::Results::Fulfilled.new(nil, 0)
28
- results << Lookout::Results::Fulfilled.new(nil, 0)
29
- end
30
4
  end
@@ -1,7 +1,4 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  Expectations do
4
- expect Lookout::Results::Error.new(nil, 0, nil, nil).to.be.error?
5
- expect Lookout::Results::Error.new(nil, 0, nil, nil).not.to.be.failure?
6
- expect Lookout::Results::Error.new(nil, 0, nil, nil).not.to.be.fulfilled?
7
4
  end
@@ -1,7 +1,4 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  Expectations do
4
- expect Lookout::Results::Failures::Behavior.new(nil, 0, nil).not.to.be.error?
5
- expect Lookout::Results::Failures::Behavior.new(nil, 0, nil).to.be.failure?
6
- expect Lookout::Results::Failures::Behavior.new(nil, 0, nil).not.to.be.fulfilled?
7
4
  end
@@ -1,7 +1,4 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  Expectations do
4
- expect Lookout::Results::Failures::State.new(nil, 0, nil).not.to.be.error?
5
- expect Lookout::Results::Failures::State.new(nil, 0, nil).to.be.failure?
6
- expect Lookout::Results::Failures::State.new(nil, 0, nil).not.to.be.fulfilled?
7
4
  end
@@ -1,7 +1,4 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  Expectations do
4
- expect Lookout::Results::Fulfilled.new(nil, 0).not.to.be.error?
5
- expect Lookout::Results::Fulfilled.new(nil, 0).not.to.be.failure?
6
- expect Lookout::Results::Fulfilled.new(nil, 0).to.be.fulfilled?
7
4
  end
@@ -0,0 +1,24 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Expectations do
4
+ expect 0 do
5
+ results = Lookout::Results::Unsuccessful.new
6
+ results << Lookout::Results::Fulfilled.new(nil, 0)
7
+ results.count
8
+ end
9
+
10
+ expect Lookout::Results::Unsuccessful.new.not.to.have.succeeded? do |results|
11
+ results << Lookout::Results::Failures::State.new(nil, 0, nil)
12
+ results << Lookout::Results::Fulfilled.new(nil, 0)
13
+ end
14
+
15
+ expect Lookout::Results::Unsuccessful.new.not.to.have.succeeded? do |results|
16
+ results << Lookout::Results::Failures::Behavior.new(nil, 0, nil)
17
+ results << Lookout::Results::Fulfilled.new(nil, 0)
18
+ end
19
+
20
+ expect Lookout::Results::Unsuccessful.new.to.have.succeeded? do |results|
21
+ results << Lookout::Results::Fulfilled.new(nil, 0)
22
+ results << Lookout::Results::Fulfilled.new(nil, 0)
23
+ end
24
+ end
@@ -0,0 +1,19 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Expectations do
4
+ expect false do
5
+ Object.new.nil?
6
+ end
7
+
8
+ expect true do
9
+ Object.new.tap{ |o|
10
+ Lookout::Stub::Methods.new.define(o, :nil?){ true }
11
+ }.nil?
12
+ end
13
+
14
+ expect false do
15
+ Object.new.tap{ |o|
16
+ Lookout::Stub::Methods.new.define(o, :nil?){ true }.undefine
17
+ }.nil?
18
+ end
19
+ end
@@ -2,10 +2,9 @@
2
2
 
3
3
  Expectations do
4
4
  expect [%r{test.*backtrace\.rb}] do
5
- expectations = Lookout::Expectations.new
6
- expectations.expect(1){ raise }
5
+ results = Lookout::Results::Unsuccessful.new
6
+ Lookout::Expectations.new(results).expect(1){ raise }
7
7
  Lookout::Results::Error::Exception::Backtrace.
8
- new(expectations.evaluate(Lookout::UI::Silent.new).first.exception.exception.backtrace,
9
- true).backtrace
8
+ new(results.first.exception.exception.backtrace, true).backtrace
10
9
  end
11
10
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lookout
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 1
9
- - 2
10
- version: 2.1.2
9
+ - 3
10
+ version: 2.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Nikolai Weibull
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-24 00:00:00 +02:00
18
+ date: 2011-07-15 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -341,7 +341,6 @@ extensions: []
341
341
  extra_rdoc_files: []
342
342
 
343
343
  files:
344
- - lib/lookout/benchmark.rb
345
344
  - lib/lookout/diff.rb
346
345
  - lib/lookout/diff/algorithms.rb
347
346
  - lib/lookout/diff/algorithms/difflib.rb
@@ -364,7 +363,6 @@ files:
364
363
  - lib/lookout/expectations/behavior.rb
365
364
  - lib/lookout/expectations/state/warning.rb
366
365
  - lib/lookout/expectations/state.rb
367
- - lib/lookout/mock.rb
368
366
  - lib/lookout/mock/method.rb
369
367
  - lib/lookout/mock/method/arguments.rb
370
368
  - lib/lookout/mock/method/arguments/any.rb
@@ -394,14 +392,15 @@ files:
394
392
  - lib/lookout/results/failures.rb
395
393
  - lib/lookout/results/failures/behavior.rb
396
394
  - lib/lookout/results/failures/state.rb
397
- - lib/lookout/results/error.rb
398
395
  - lib/lookout/results/error/exception.rb
399
396
  - lib/lookout/results/error/exception/backtrace.rb
400
- - lib/lookout/results/failure.rb
397
+ - lib/lookout/results/unsuccessful.rb
398
+ - lib/lookout/results/error.rb
401
399
  - lib/lookout/results/fulfilled.rb
400
+ - lib/lookout/results/instance.rb
401
+ - lib/lookout/results/failure.rb
402
402
  - lib/lookout/runners.rb
403
403
  - lib/lookout/runners/console.rb
404
- - lib/lookout/stub.rb
405
404
  - lib/lookout/stub/method.rb
406
405
  - lib/lookout/stub/methods.rb
407
406
  - lib/lookout/stub/object.rb
@@ -410,15 +409,27 @@ files:
410
409
  - lib/lookout/ui/console.rb
411
410
  - lib/lookout/xml.rb
412
411
  - lib/lookout/aphonic.rb
413
- - lib/lookout/result.rb
414
- - lib/lookout/results.rb
415
412
  - lib/lookout/recorder.rb
416
413
  - lib/lookout/recorders.rb
417
- - lib/lookout/expectations.rb
414
+ - lib/lookout/version.rb
418
415
  - lib/lookout/expectation.rb
419
- - lib/lookout/warning.rb
416
+ - lib/lookout/expectations.rb
417
+ - lib/lookout/equalities/object.rb
418
+ - lib/lookout/equalities/include.rb
419
+ - lib/lookout/equalities/boolean.rb
420
+ - lib/lookout/equalities/string.rb
421
+ - lib/lookout/equalities/array.rb
422
+ - lib/lookout/equalities/hash.rb
423
+ - lib/lookout/equalities/standarderror.rb
424
+ - lib/lookout/equalities/output.rb
425
+ - lib/lookout/equalities/warning.rb
420
426
  - lib/lookout/equality.rb
421
- - lib/lookout/version.rb
427
+ - lib/lookout/warning.rb
428
+ - lib/lookout/mock.rb
429
+ - lib/lookout/stub.rb
430
+ - lib/lookout/results.rb
431
+ - lib/lookout/result.rb
432
+ - lib/lookout/equalities.rb
422
433
  - lib/lookout.rb
423
434
  - test/unit/lookout.rb
424
435
  - test/unit/lookout/diff.rb
@@ -438,25 +449,25 @@ files:
438
449
  - test/unit/lookout/diff/range.rb
439
450
  - test/unit/lookout/equality.rb
440
451
  - test/unit/lookout/expectation.rb
441
- - test/unit/lookout/expectations.rb
442
- - test/unit/lookout/expectations/behavior.rb
443
452
  - test/unit/lookout/expectations/state.rb
444
- - test/unit/lookout/mock.rb
453
+ - test/unit/lookout/expectations/behavior.rb
445
454
  - test/unit/lookout/mock/method.rb
446
455
  - test/unit/lookout/mock/method/arguments.rb
447
456
  - test/unit/lookout/mock/method/arguments/any.rb
448
457
  - test/unit/lookout/recorder.rb
449
- - test/unit/lookout/results.rb
450
- - test/unit/lookout/results/error.rb
451
458
  - test/unit/lookout/results/failures/behavior.rb
452
459
  - test/unit/lookout/results/failures/state.rb
460
+ - test/unit/lookout/results/unsuccessful.rb
461
+ - test/unit/lookout/results/error.rb
453
462
  - test/unit/lookout/results/fulfilled.rb
454
463
  - test/unit/lookout/runners/console.rb
455
- - test/unit/lookout/stub.rb
456
464
  - test/unit/lookout/stub/method.rb
465
+ - test/unit/lookout/stub/methods.rb
457
466
  - test/unit/lookout/ui/formatters/exception.rb
458
467
  - test/unit/lookout/ui/formatters/exception/backtrace.rb
459
468
  - test/unit/lookout/xml.rb
469
+ - test/unit/lookout/results.rb
470
+ - test/unit/lookout/expectations.rb
460
471
  - test/unit/examples.rb
461
472
  - README
462
473
  - Rakefile
@@ -1,11 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- module Lookout::Benchmark
4
- class << self
5
- def time
6
- start = Time.now.to_f
7
- yield
8
- Time.now.to_f - start
9
- end
10
- end
11
- end
@@ -1,4 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- Expectations do
4
- end
@@ -1,4 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- Expectations do
4
- end