kookaburra 0.14.2 → 0.14.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.14.2
1
+ 0.14.3
data/kookaburra.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "kookaburra"
8
- s.version = "0.14.2"
8
+ s.version = "0.14.3"
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"]
12
- s.date = "2012-02-01"
12
+ s.date = "2012-02-22"
13
13
  s.description = "Cucumber + Capybara = Kookaburra? It made sense at the time."
14
14
  s.email = "devteam@renewfund.com"
15
15
  s.extra_rdoc_files = [
@@ -40,6 +40,7 @@ Gem::Specification.new do |s|
40
40
  "test/helper.rb",
41
41
  "test/kookaburra/assertion_test.rb",
42
42
  "test/kookaburra/test_data_test.rb",
43
+ "test/kookaburra/ui_driver/mixins/has_browser_test.rb",
43
44
  "test/kookaburra/ui_driver/ui_component_test.rb",
44
45
  "test/kookaburra/ui_driver_test.rb",
45
46
  "test/kookaburra_test.rb"
@@ -47,7 +48,7 @@ Gem::Specification.new do |s|
47
48
  s.homepage = "http://github.com/projectdx/kookaburra"
48
49
  s.licenses = ["MIT"]
49
50
  s.require_paths = ["lib"]
50
- s.rubygems_version = "1.8.15"
51
+ s.rubygems_version = "1.8.16"
51
52
  s.summary = "WindowDriver testing pattern for Ruby apps"
52
53
 
53
54
  if s.respond_to? :specification_version then
@@ -21,7 +21,7 @@ module Kookaburra
21
21
  # Does not wait, so should only be used after failing a check
22
22
  # for being in the expected place.
23
23
  def no_500_error!
24
- return if browser.all(:css, 'head title', :text => 'Internal Server Error').empty?
24
+ return true if browser.all(:css, 'head title', :text => 'Internal Server Error').empty?
25
25
  sleep 30 if ENV['GIMME_CRAP']
26
26
  raise Unexpected500, browser.body
27
27
  end
@@ -46,16 +46,16 @@ module Kookaburra
46
46
  end
47
47
 
48
48
  # Default implementation navigates directly to this UIComponent's
49
- # `#component_path`. If `opts[:query_params]` is set to a Hash, the
50
- # request will be made with the resulting querystring on the URL.
51
- def show(opts = {})
49
+ # `#component_path`.
50
+ #
51
+ # @param path_args [Argument List] Any arguments added to this method are
52
+ # passed through to `#component_path`.
53
+ def show(*path_args)
52
54
  unless respond_to?(:component_path)
53
- raise "You must either set component_path or redefine the #show method in UIComponent subclasses!"
55
+ raise NoMethodError, "You must either set component_path or redefine the #show method in UIComponent subclasses!"
54
56
  end
55
57
  return if visible?
56
- path = component_path
57
- path << ( '?' + opts[:query_params].map{|kv| "%s=%s" % kv}.join('&') ) if opts[:query_params]
58
- visit path
58
+ visit component_path(*path_args)
59
59
  end
60
60
 
61
61
  def refresh
data/lib/kookaburra.rb CHANGED
@@ -9,7 +9,19 @@ require 'kookaburra/ui_driver'
9
9
  # {file:README.markdown README} for more information on setting up Kookaburra
10
10
  # for your project.
11
11
  module Kookaburra
12
+ ConfigurationError = Class.new(RuntimeError)
13
+
12
14
  class << self
15
+ def self.config_var(*names)
16
+ names.each do |name|
17
+ attr_accessor name
18
+ define_method(name) do
19
+ instance_variable_get("@#{name}") \
20
+ or raise ConfigurationError.new("Please specify Kookaburra.#{name} in your configuration.")
21
+ end
22
+ end
23
+ end
24
+
13
25
  # Provides the default adapter for the Kookaburra library.
14
26
  #
15
27
  # If not using Capybara, the Object must respond to `#app` and return a Rack
@@ -18,25 +30,37 @@ module Kookaburra
18
30
  #
19
31
  # @example using Capybara
20
32
  # Kookaburra.adapter = Capybara
21
- attr_accessor :adapter
33
+ #
34
+ # @raise [ConfigurationError] raised by reader method if no adapter has been
35
+ # assigned yet.
36
+ config_var :adapter
22
37
 
23
38
  # A reference to your application's subclass of `Kookaburra::APIDriver`
24
39
  #
25
40
  # @example setting your APIDriver
26
41
  # Kookaburra.api_driver = MyApplication::Kookaburra::APIDriver
27
- attr_accessor :api_driver
42
+ #
43
+ # @raise [ConfigurationError] raised by reader method if no api driver class
44
+ # has been assigned yet.
45
+ config_var :api_driver
28
46
 
29
47
  # A reference to your application's subclass of `Kookaburra::GivenDriver`
30
48
  #
31
49
  # @example setting your GivenDriver
32
50
  # Kookaburra.api_driver = MyApplication::Kookaburra::GivenDriver
33
- attr_accessor :given_driver
51
+ #
52
+ # @raise [ConfigurationError] raised by reader method if no given driver
53
+ # class has been assigned yet.
54
+ config_var :given_driver
34
55
 
35
56
  # A reference to your application's subclass of `Kookaburra::UIDriver`
36
57
  #
37
58
  # @example setting your UIDriver
38
59
  # Kookaburra.api_driver = MyApplication::Kookaburra::UIDriver
39
- attr_accessor :ui_driver
60
+ #
61
+ # @raise [ConfigurationError] raised by reader method if no ui driver
62
+ # class has been assigned yet.
63
+ config_var :ui_driver
40
64
 
41
65
  # Configure the test data collections and default data for your tests
42
66
  #
data/test/helper.rb CHANGED
@@ -15,6 +15,16 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
15
15
  require 'kookaburra'
16
16
 
17
17
  class MiniTest::Unit::TestCase
18
+ # TODO: make this better, so that there is only one failure message
19
+ def assert_raises_with_message(expected_exception, expected_message, &block)
20
+ begin
21
+ yield
22
+ flunk "Expected to raise a #{expected_exception}"
23
+ rescue => e
24
+ assert_kind_of expected_exception, e
25
+ assert_match expected_message, e.message
26
+ end
27
+ end
18
28
  end
19
29
 
20
30
  MiniTest::Unit.autorun
@@ -0,0 +1,38 @@
1
+ require 'helper'
2
+
3
+ describe Kookaburra::UIDriver::HasBrowser do
4
+ describe '#no_500_error!' do
5
+ let(:klass) do
6
+ Class.new do
7
+ include Kookaburra::UIDriver::HasBrowser
8
+
9
+ def run_test
10
+ no_500_error!
11
+ end
12
+ end
13
+ end
14
+
15
+ let(:browser) do
16
+ b = MiniTest::Mock.new
17
+ def b.body; 'Hello'; end
18
+ b
19
+ end
20
+
21
+ let(:obj) { klass.new(:browser => browser) }
22
+
23
+ it 'raises Unexpected500 if the page title is "Internal Server Error"' do
24
+ browser.expect(:all, [:not_empty],
25
+ [:css, 'head title', {:text => 'Internal Server Error'}])
26
+
27
+ assert_raises Kookaburra::UIDriver::HasBrowser::Unexpected500 do
28
+ obj.run_test
29
+ end
30
+ end
31
+
32
+ it 'returns true if the page title is not "Internal Server Error"' do
33
+ browser.expect(:all, [],
34
+ [:css, 'head title', {:text => 'Internal Server Error'}])
35
+ assert_equal true, obj.run_test
36
+ end
37
+ end
38
+ end
@@ -49,4 +49,53 @@ describe Kookaburra::UIDriver::UIComponent do
49
49
  assert_equal 3, component.count('.element')
50
50
  end
51
51
  end
52
+
53
+ describe '#show' do
54
+ let(:browser) { MiniTest::Mock.new }
55
+ let(:component) do
56
+ c = Kookaburra::UIDriver::UIComponent.new(:browser => browser)
57
+ def c.no_500_error!; true; end
58
+ c
59
+ end
60
+
61
+ it 'raises a NoMethodError if #component_path is not defined' do
62
+ assert_raises_with_message(NoMethodError, /set component_path/) do
63
+ component.show
64
+ end
65
+ end
66
+
67
+ describe "when the component is not already visible" do
68
+ before(:each) do
69
+ def component.visible?; false; end
70
+ end
71
+
72
+ it 'visits the path returned by #component_path' do
73
+ def component.component_path; '/my/path'; end
74
+ browser.expect(:visit, nil, ['/my/path'])
75
+ component.show
76
+ end
77
+
78
+ it 'passes any arguments through to #component_path' do
79
+ def browser.visit(*args); nil; end
80
+
81
+ def component.component_path(*args)
82
+ unless args == %w[one two three]
83
+ raise "Expected #component_path('one', 'two', 'three') but called with #{args.inspect}"
84
+ end
85
+ end
86
+
87
+ component.show('one', 'two', 'three')
88
+ end
89
+ end
90
+
91
+ describe "when the component is already visible" do
92
+ it 'does not visit the component path' do
93
+ def component.component_path; '/my/path'; end
94
+ def component.visible?; true; end
95
+
96
+ def browser.visit(*args); raise "Shouldn't get called"; end
97
+ component.show
98
+ end
99
+ end
100
+ end
52
101
  end
@@ -48,7 +48,7 @@ describe Kookaburra do
48
48
 
49
49
  it 'defaults to the value of Kookaburra.adapter' do
50
50
  begin
51
- old_adapter = Kookaburra.adapter
51
+ old_adapter = Kookaburra.adapter rescue nil
52
52
  Kookaburra.adapter = :global_adapter
53
53
  mixer = mixer_class.new
54
54
  assert_equal :global_adapter, mixer.kookaburra_adapter
@@ -133,10 +133,16 @@ describe Kookaburra do
133
133
  describe 'methods on the Kookaburra object' do
134
134
  describe '#adapter' do
135
135
  it 'is a read/write attribute' do
136
- assert_nil Kookaburra.adapter
137
136
  Kookaburra.adapter = :probably_Capybara
138
137
  assert_equal :probably_Capybara, Kookaburra.adapter
139
138
  end
139
+
140
+ it 'raises an exception when it is read while nil' do
141
+ assert_raises Kookaburra::ConfigurationError do
142
+ Kookaburra.adapter = nil
143
+ Kookaburra.adapter
144
+ end
145
+ end
140
146
  end
141
147
 
142
148
  describe '#api_driver' do
@@ -144,6 +150,13 @@ describe Kookaburra do
144
150
  Kookaburra.api_driver = :an_api_driver
145
151
  assert_equal :an_api_driver, Kookaburra.api_driver
146
152
  end
153
+
154
+ it 'raises an exception when it is read while nil' do
155
+ assert_raises Kookaburra::ConfigurationError do
156
+ Kookaburra.api_driver = nil
157
+ Kookaburra.api_driver
158
+ end
159
+ end
147
160
  end
148
161
 
149
162
  describe '#given_driver' do
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: 35
4
+ hash: 33
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 14
9
- - 2
10
- version: 0.14.2
9
+ - 3
10
+ version: 0.14.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Renewable Funding, LLC
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-02-01 00:00:00 Z
18
+ date: 2012-02-22 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement
@@ -192,6 +192,7 @@ files:
192
192
  - test/helper.rb
193
193
  - test/kookaburra/assertion_test.rb
194
194
  - test/kookaburra/test_data_test.rb
195
+ - test/kookaburra/ui_driver/mixins/has_browser_test.rb
195
196
  - test/kookaburra/ui_driver/ui_component_test.rb
196
197
  - test/kookaburra/ui_driver_test.rb
197
198
  - test/kookaburra_test.rb
@@ -224,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
224
225
  requirements: []
225
226
 
226
227
  rubyforge_project:
227
- rubygems_version: 1.8.15
228
+ rubygems_version: 1.8.16
228
229
  signing_key:
229
230
  specification_version: 3
230
231
  summary: WindowDriver testing pattern for Ruby apps