kookaburra 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/.yardopts CHANGED
@@ -1 +1,2 @@
1
1
  --markup=markdown
2
+ --no-private
data/README.markdown CHANGED
@@ -129,17 +129,23 @@ definitions, RSpec example blocks, Test::Unit tests, etc. At this layer, your
129
129
  code orchestrates calls into the Domain Driver to mimic user interactions under
130
130
  various conditions and make assertions about the results.
131
131
 
132
- **Assertions always belong within the test implementation layer.** Some testing
132
+ **Test assertions always belong within the test implementation layer.** Some testing
133
133
  frameworks such as RSpec add methods like `#should` to `Object`, which has the
134
134
  effect of poisoning the entire Ruby namespace with these methods---if you are
135
135
  using RSpec, you can call `#should` anywhere in your code and it will work when
136
136
  RSpec is loaded. Do not be tempted to call a testing library's Object decorators
137
137
  anywhere outside of your test implementation (such as within `UIDriver` or
138
138
  `UIComponent` subclasses.) Doing so will tightly couple your Domain Driver
139
- and/or Window Driver implementation to a specific testing library. If you must
140
- make some type of assertion within the Domain Driver layer, a better approach is
141
- to simply raise an exception with an informative error message when some desired
142
- condition is not met.
139
+ and/or Window Driver implementation to a specific testing library.
140
+
141
+ If you must make some type of assertion within the Domain Driver layer, a better
142
+ approach is to simply raise an exception with an informative error message when
143
+ some desired condition is not met. Kookaburra provides its own `#assert` method
144
+ for this purpose. You may use it directly or build your own custom assertions
145
+ using it as a base. However, this method should be used only for the purpose
146
+ of short-circuiting your Domain Driver with an informative error message, not
147
+ to test the results of your operations as you would at the test implementation
148
+ layer.
143
149
 
144
150
  Given the Cucumber scenario above, here is how the test implementation layer
145
151
  might look:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.0
1
+ 0.9.0
data/kookaburra.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "kookaburra"
8
- s.version = "0.8.0"
8
+ s.version = "0.9.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Renewable Funding, LLC"]
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
29
29
  "kookaburra.gemspec",
30
30
  "lib/kookaburra.rb",
31
31
  "lib/kookaburra/api_driver.rb",
32
+ "lib/kookaburra/assertion.rb",
32
33
  "lib/kookaburra/given_driver.rb",
33
34
  "lib/kookaburra/test_data.rb",
34
35
  "lib/kookaburra/ui_driver.rb",
@@ -38,6 +39,7 @@ Gem::Specification.new do |s|
38
39
  "lib/kookaburra/ui_driver/mixins/has_ui_component.rb",
39
40
  "lib/kookaburra/ui_driver/ui_component.rb",
40
41
  "test/helper.rb",
42
+ "test/kookaburra/assertion_test.rb",
41
43
  "test/kookaburra/test_data_test.rb",
42
44
  "test/kookaburra/ui_driver_test.rb",
43
45
  "test/kookaburra_test.rb"
@@ -2,6 +2,8 @@ require 'rack/test'
2
2
 
3
3
  module Kookaburra
4
4
  class APIDriver
5
+ include Kookaburra::Assertion
6
+
5
7
  def initialize(opts)
6
8
  @app = opts.fetch(:app)
7
9
  end
@@ -0,0 +1,32 @@
1
+ module Kookaburra
2
+ module Assertion
3
+ # Custom exception class for assertion failures
4
+ class Failure < Exception; end
5
+
6
+ # Provides a mechanism for making assertions within your domain and window drivers
7
+ # without creating a dependency on any specific testing framework.
8
+ #
9
+ # @param [Truthy] predicate The thing you are asserting should be `true` (or at least truthy).
10
+ # @param [String] message Optional message to return if `predicate` is not `true` (or at least truthy).
11
+ # @return [nil] if `predicate` does not evaluate to `false` or `nil`
12
+ # @raise [Kookaburra::Assertion::Failure] if `predicate` evaluates to `false` or `nil`
13
+ def assert(predicate, message = nil)
14
+ return if predicate
15
+ raise Failure, message
16
+ rescue Failure => e
17
+ raise Backtrace.clean(e)
18
+ end
19
+
20
+ # @private
21
+ module Backtrace
22
+ module_function
23
+
24
+ def clean(exception)
25
+ new_backtrace = exception.backtrace.dup
26
+ new_backtrace.shift while new_backtrace.first.include?('lib/kookaburra/assertion.rb')
27
+ exception.set_backtrace(new_backtrace)
28
+ exception
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,5 +1,7 @@
1
1
  module Kookaburra
2
2
  class GivenDriver
3
+ include Kookaburra::Assertion
4
+
3
5
  attr_reader :api
4
6
  attr_reader :test_data
5
7
 
@@ -5,6 +5,7 @@ require 'kookaburra/ui_driver/mixins/has_subcomponents'
5
5
  module Kookaburra
6
6
  class UIDriver
7
7
  class UIComponent
8
+ include Kookaburra::Assertion
8
9
  include HasBrowser
9
10
  include HasStrategies
10
11
  extend HasSubcomponents
@@ -3,6 +3,7 @@ require 'kookaburra/ui_driver/mixins/has_ui_component'
3
3
 
4
4
  module Kookaburra
5
5
  class UIDriver
6
+ include Kookaburra::Assertion
6
7
  include HasBrowser
7
8
  include HasUIComponent
8
9
 
data/lib/kookaburra.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'kookaburra/assertion'
1
2
  require 'kookaburra/test_data'
2
3
  require 'kookaburra/api_driver'
3
4
  require 'kookaburra/given_driver'
@@ -0,0 +1,68 @@
1
+ require 'helper'
2
+
3
+ describe Kookaburra::Assertion do
4
+ let(:api) { Class.new(Kookaburra::APIDriver).new({:app => nil}) }
5
+ let(:given) { Class.new(Kookaburra::GivenDriver).new({:api_driver => api, :test_data => nil}) }
6
+ let(:ui_component) { Class.new(Kookaburra::UIDriver::UIComponent).new(:test_data => nil) }
7
+ let(:ui) { ui_class.new }
8
+ let(:ui_class) do
9
+ Class.new(Kookaburra::UIDriver) do
10
+ def positive_assertion
11
+ assert true
12
+ end
13
+
14
+ def negative_assertion
15
+ assert false
16
+ end
17
+
18
+ def negative_assertion_with_message
19
+ assert false, "Hello, world!"
20
+ end
21
+ end
22
+ end
23
+
24
+ it 'should be included in Kookaburra::APIDriver' do
25
+ assert_kind_of Kookaburra::Assertion, api
26
+ end
27
+ it 'should be included in Kookaburra::GivenDriver' do
28
+ assert_kind_of Kookaburra::Assertion, given
29
+ end
30
+ it 'should be included in Kookaburra::UIDriver' do
31
+ assert_kind_of Kookaburra::Assertion, ui
32
+ end
33
+ it 'should be included in Kookaburra::UIDriver::UIComponent' do
34
+ assert_kind_of Kookaburra::Assertion, ui_component
35
+ end
36
+
37
+ it 'should be able to make a positive assertion' do
38
+ ui.positive_assertion
39
+ end
40
+
41
+ it 'should be able to make a negative assertion' do
42
+ assert_raises(Kookaburra::Assertion::Failure) do
43
+ ui.negative_assertion
44
+ end
45
+ end
46
+
47
+ it 'should be able to make a negative assertion with a custom failure message' do
48
+ begin
49
+ ui.negative_assertion_with_message
50
+ rescue Kookaburra::Assertion::Failure => e
51
+ assert_equal 'Hello, world!', e.message
52
+ end
53
+ end
54
+
55
+ describe Kookaburra::Assertion::Failure do
56
+ let(:base_path) { File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. lib kookaburra])) }
57
+
58
+ it 'removes lines including assertion.rb from the top of its backtrace' do
59
+ begin
60
+ ui.negative_assertion
61
+ rescue Kookaburra::Assertion::Failure => e
62
+ assert e.backtrace.none? { |line| line.include?('lib/kookaburra/assertion.rb') },
63
+ '"assertion.rb" should be cleaned from backtrace'
64
+ end
65
+ end
66
+ end
67
+
68
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kookaburra
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 59
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 8
8
+ - 9
9
9
  - 0
10
- version: 0.8.0
10
+ version: 0.9.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Renewable Funding, LLC
@@ -181,6 +181,7 @@ files:
181
181
  - kookaburra.gemspec
182
182
  - lib/kookaburra.rb
183
183
  - lib/kookaburra/api_driver.rb
184
+ - lib/kookaburra/assertion.rb
184
185
  - lib/kookaburra/given_driver.rb
185
186
  - lib/kookaburra/test_data.rb
186
187
  - lib/kookaburra/ui_driver.rb
@@ -190,6 +191,7 @@ files:
190
191
  - lib/kookaburra/ui_driver/mixins/has_ui_component.rb
191
192
  - lib/kookaburra/ui_driver/ui_component.rb
192
193
  - test/helper.rb
194
+ - test/kookaburra/assertion_test.rb
193
195
  - test/kookaburra/test_data_test.rb
194
196
  - test/kookaburra/ui_driver_test.rb
195
197
  - test/kookaburra_test.rb