kookaburra 0.17.1 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,5 +1,8 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
+ # Only need this gem for Ruby < 1.9.2
4
+ gem 'basic_object' unless defined?(BasicObject)
5
+
3
6
  gem 'i18n'
4
7
  gem 'activesupport', '>= 3.0'
5
8
  gem 'rack-test'
data/Gemfile.lock CHANGED
@@ -4,6 +4,7 @@ GEM
4
4
  activesupport (3.2.2)
5
5
  i18n (~> 0.6)
6
6
  multi_json (~> 1.0)
7
+ basic_object (0.0.1)
7
8
  capybara (1.1.2)
8
9
  mime-types (>= 1.16)
9
10
  nokogiri (>= 1.3.3)
@@ -74,6 +75,7 @@ PLATFORMS
74
75
 
75
76
  DEPENDENCIES
76
77
  activesupport (>= 3.0)
78
+ basic_object
77
79
  capybara
78
80
  i18n
79
81
  jeweler
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.17.1
1
+ 0.18.0
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.17.1"
8
+ s.version = "0.18.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["John Wilger", "Sam Livingston-Gray", "Ravi Gadad"]
12
- s.date = "2012-03-17"
12
+ s.date = "2012-03-18"
13
13
  s.description = "Cucumber + Capybara = Kookaburra? It made sense at the time."
14
14
  s.email = "johnwilger@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -34,6 +34,7 @@ Gem::Specification.new do |s|
34
34
  "lib/kookaburra/exceptions.rb",
35
35
  "lib/kookaburra/given_driver.rb",
36
36
  "lib/kookaburra/json_api_driver.rb",
37
+ "lib/kookaburra/null_browser.rb",
37
38
  "lib/kookaburra/rack_driver.rb",
38
39
  "lib/kookaburra/test_data.rb",
39
40
  "lib/kookaburra/test_helpers.rb",
@@ -41,6 +42,7 @@ Gem::Specification.new do |s|
41
42
  "lib/kookaburra/ui_driver/ui_component.rb",
42
43
  "lib/kookaburra/utils/active_record_shared_connection.rb",
43
44
  "spec/kookaburra/json_api_driver_spec.rb",
45
+ "spec/kookaburra/null_browser_spec.rb",
44
46
  "spec/kookaburra/rack_driver_spec.rb",
45
47
  "spec/kookaburra/test_data_spec.rb",
46
48
  "spec/kookaburra/test_helpers_spec.rb",
@@ -60,6 +62,7 @@ Gem::Specification.new do |s|
60
62
  s.specification_version = 3
61
63
 
62
64
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
65
+ s.add_runtime_dependency(%q<basic_object>, [">= 0"])
63
66
  s.add_runtime_dependency(%q<i18n>, [">= 0"])
64
67
  s.add_runtime_dependency(%q<activesupport>, [">= 3.0"])
65
68
  s.add_runtime_dependency(%q<rack-test>, [">= 0"])
@@ -72,6 +75,7 @@ Gem::Specification.new do |s|
72
75
  s.add_development_dependency(%q<reek>, [">= 0"])
73
76
  s.add_development_dependency(%q<sinatra>, [">= 0"])
74
77
  else
78
+ s.add_dependency(%q<basic_object>, [">= 0"])
75
79
  s.add_dependency(%q<i18n>, [">= 0"])
76
80
  s.add_dependency(%q<activesupport>, [">= 3.0"])
77
81
  s.add_dependency(%q<rack-test>, [">= 0"])
@@ -85,6 +89,7 @@ Gem::Specification.new do |s|
85
89
  s.add_dependency(%q<sinatra>, [">= 0"])
86
90
  end
87
91
  else
92
+ s.add_dependency(%q<basic_object>, [">= 0"])
88
93
  s.add_dependency(%q<i18n>, [">= 0"])
89
94
  s.add_dependency(%q<activesupport>, [">= 3.0"])
90
95
  s.add_dependency(%q<rack-test>, [">= 0"])
@@ -9,4 +9,6 @@ class Kookaburra
9
9
  class AssertionFailed < RuntimeError; end
10
10
  # @private
11
11
  class ComponentNotFound < RuntimeError; end
12
+ # @private
13
+ class NullBrowserError < ConfigurationError; end
12
14
  end
@@ -0,0 +1,10 @@
1
+ require 'basic_object'
2
+
3
+ class Kookaburra
4
+ class NullBrowser < BasicObject
5
+ def method_missing(*args)
6
+ raise NullBrowserError,
7
+ "You did not provide a :browser to the Kookaburra configuration, but you tried to use one anyway."
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,5 @@
1
+ require 'delegate'
2
+
1
3
  class Kookaburra
2
4
  # Each instance of {Kookaburra} has its own instance of TestData. This object
3
5
  # is used to maintain a shared understanding of the application state between
@@ -38,14 +40,15 @@ class Kookaburra
38
40
  #
39
41
  # # Raises an UnknownKeyError
40
42
  # test_data.widgets[:bar]
41
- class Collection
43
+ class Collection < SimpleDelegator
42
44
  # @param [String] name The name of the collection. Used to provide
43
45
  # helpful error messages when unknown keys are accessed.
44
46
  def initialize(name)
45
47
  @name = name
46
- @data = Hash.new do |hash, key|
48
+ data = Hash.new do |hash, key|
47
49
  raise UnknownKeyError, "Can't find test_data.#{@name}[#{key.inspect}]. Did you forget to set it?"
48
50
  end
51
+ super(data)
49
52
  end
50
53
 
51
54
  # Unlike a Hash, this object is only identical to another if the actual
@@ -69,21 +72,9 @@ class Kookaburra
69
72
  # not been set
70
73
  def slice(*keys)
71
74
  results = keys.map do |key|
72
- @data[key]
75
+ self[key]
73
76
  end
74
77
  end
75
-
76
- # Any unknown messages are passed to the underlying data collection, which
77
- # is a Hash.
78
- def method_missing(name, *args, &block)
79
- return super unless respond_to?(name)
80
- @data.send(name, *args, &block)
81
- end
82
-
83
- # @private
84
- def respond_to?(name)
85
- super || @data.respond_to?(name)
86
- end
87
78
  end
88
79
  end
89
80
  end
@@ -1,5 +1,4 @@
1
1
  require 'kookaburra/exceptions'
2
- require 'kookaburra/dependency_accessor'
3
2
 
4
3
  class Kookaburra
5
4
  class UIDriver
@@ -66,8 +65,6 @@ class Kookaburra
66
65
  # you override the default implementation of {#show}, you must also
67
66
  # override the {#component_path} method.
68
67
  class UIComponent
69
- extend DependencyAccessor
70
-
71
68
  # New UIComponent instances are typically created for you by your
72
69
  # {Kookaburra::UIDriver} instance.
73
70
  #
@@ -82,7 +79,8 @@ class Kookaburra
82
79
  end
83
80
 
84
81
  # If the UIComponent is sent a message it does not understand, it will
85
- # forward that message on to its {#browser}. This provides convenient
82
+ # forward that message on to its {#browser} but wrap the call in a block
83
+ # provided to the the browser's `#within` method. This provides convenient
86
84
  # access to the browser driver's DSL, automatically scoped to this
87
85
  # component.
88
86
  def method_missing(name, *args, &block)
@@ -135,11 +133,12 @@ class Kookaburra
135
133
  protected
136
134
 
137
135
  # This is the browser driver with which the UIComponent was initialized.
138
- #
139
- # @attribute [r] browser
140
- #
141
- # @raise [RuntimeError] if no browser was specified in call to {#initialize}
142
- dependency_accessor :browser
136
+ #
137
+ # If no :browser option was specified in {#initialize}, it returns a
138
+ # default {Kookaburra::NullBrowser} instance.
139
+ def browser
140
+ @browser ||= NullBrowser.new
141
+ end
143
142
 
144
143
  # Provides a mechanism to make assertions about the state of your
145
144
  # UIComponent without relying on a specific testing framework. A good
@@ -48,7 +48,7 @@ class Kookaburra
48
48
  # this component.
49
49
  def ui_component(component_name, component_class)
50
50
  define_method(component_name) do
51
- component_class.new(:browser => browser, :server_error_detection => @server_error_detection)
51
+ component_class.new(:browser => @browser, :server_error_detection => @server_error_detection)
52
52
  end
53
53
  end
54
54
  end
@@ -70,9 +70,6 @@ class Kookaburra
70
70
 
71
71
  protected
72
72
 
73
- # @attribute [r] browser
74
- dependency_accessor :browser
75
-
76
73
  # @attribute [r] test_data
77
74
  dependency_accessor :test_data
78
75
  end
data/lib/kookaburra.rb CHANGED
@@ -42,10 +42,11 @@ class Kookaburra
42
42
  # Kookaburra is intended to work with `Capybara::Session` as a browser
43
43
  # driver, but you could use something else that exposed the same basic API.
44
44
  def initialize(options = {})
45
- @api_driver_class = options[:api_driver_class]
46
- @given_driver_class = options[:given_driver_class]
47
- @ui_driver_class = options[:ui_driver_class]
48
- @browser = options[:browser]
45
+ @api_driver_class = options[:api_driver_class]
46
+ @given_driver_class = options[:given_driver_class]
47
+ @ui_driver_class = options[:ui_driver_class]
48
+ @browser = options[:browser]
49
+ @rack_app = options[:rack_app]
49
50
  @server_error_detection = options[:server_error_detection]
50
51
  end
51
52
 
@@ -91,14 +92,21 @@ class Kookaburra
91
92
  private
92
93
 
93
94
  extend DependencyAccessor
94
- dependency_accessor :given_driver_class, :api_driver_class, :ui_driver_class, :browser
95
+ dependency_accessor :given_driver_class, :api_driver_class, :ui_driver_class
95
96
 
96
97
  def api
97
- api_driver_class.new(RackDriver.new(browser.app))
98
+ api_driver_class.new(application_driver)
99
+ end
100
+
101
+ def application_driver
102
+ RackDriver.new(@rack_app)
98
103
  end
99
104
 
100
105
  def test_data
101
106
  @test_data ||= TestData.new
102
107
  end
103
108
 
109
+ def browser
110
+ @browser ||= NullBrowser.new
111
+ end
104
112
  end
@@ -0,0 +1,15 @@
1
+ require 'kookaburra/null_browser'
2
+
3
+ describe Kookaburra::NullBrowser do
4
+ it 'is a BasicObject' do
5
+ pending "Not sure how to test this, since a BasicObject doesn't implement #kind_of?, etc." do
6
+ subject.kind_of?(BasicObject).should == true
7
+ end
8
+ end
9
+
10
+ it 'raises a NullBrowserError when any methods are called on it' do
11
+ lambda { subject.app }.should raise_error(
12
+ Kookaburra::NullBrowserError,
13
+ "You did not provide a :browser to the Kookaburra configuration, but you tried to use one anyway.")
14
+ end
15
+ end
@@ -1,5 +1,4 @@
1
1
  require 'kookaburra/ui_driver/ui_component'
2
- require 'support/shared_examples/it_has_a_dependency_accessor'
3
2
 
4
3
  describe Kookaburra::UIDriver::UIComponent do
5
4
  describe '#show' do
@@ -154,9 +153,5 @@ describe Kookaburra::UIDriver::UIComponent do
154
153
  .should raise_error(Kookaburra::AssertionFailed, "False isn't true, dummy.")
155
154
  end
156
155
  end
157
-
158
- it_behaves_like :it_has_a_dependency_accessor, :browser do
159
- let(:subject_class) { Kookaburra::UIDriver::UIComponent }
160
- end
161
156
  end
162
157
  end
@@ -22,6 +22,5 @@ describe Kookaburra::UIDriver do
22
22
  let(:subject_class) { Kookaburra::UIDriver }
23
23
 
24
24
  it_behaves_like :it_has_a_dependency_accessor, :test_data
25
- it_behaves_like :it_has_a_dependency_accessor, :browser
26
25
  end
27
26
  end
@@ -285,10 +285,11 @@ describe 'Kookaburra Integration' do
285
285
  }
286
286
 
287
287
  k = Kookaburra.new({
288
- :ui_driver_class => MyUIDriver,
289
- :given_driver_class => MyGivenDriver,
290
- :api_driver_class => MyAPIDriver,
291
- :browser => Capybara::Session.new(:rack_test, my_app),
288
+ :ui_driver_class => MyUIDriver,
289
+ :given_driver_class => MyGivenDriver,
290
+ :api_driver_class => MyAPIDriver,
291
+ :browser => Capybara::Session.new(:rack_test, my_app),
292
+ :rack_app => my_app,
292
293
  :server_error_detection => server_error_detection
293
294
  })
294
295
 
@@ -309,4 +310,39 @@ describe 'Kookaburra Integration' do
309
310
  end
310
311
  end
311
312
  end
313
+
314
+ describe "testing a Ruby API" do
315
+ class MyUIDriver < Kookaburra::UIDriver
316
+ end
317
+
318
+ class MyGivenDriver < Kookaburra::GivenDriver
319
+ end
320
+
321
+ class APIDriver < Kookaburra::APIDriver
322
+ end
323
+
324
+ it "runs the tests" do
325
+ k = Kookaburra.new({
326
+ :api_driver_class => MyAPIDriver,
327
+ :given_driver_class => MyGivenDriver,
328
+ :ui_driver_class => MyUIDriver,
329
+ })
330
+
331
+ pending 'WIP' do
332
+ k.given.a_user(:bob)
333
+ k.given.a_widget(:widget_a)
334
+ k.given.a_widget(:widget_b, :name => 'Foo')
335
+
336
+ k.ui.sign_in(:bob)
337
+ k.ui.widget_list.show
338
+ k.ui.widget_list.widgets.should == k.get_data(:widgets).slice(:widget_a, :widget_b)
339
+
340
+ k.ui.create_new_widget(:widget_c, :name => 'Bar')
341
+ k.ui.widget_list.widgets.should == k.get_data(:widgets).slice(:widget_a, :widget_b, :widget_c)
342
+
343
+ k.ui.delete_widget(:widget_b)
344
+ k.ui.widget_list.widgets.should == k.get_data(:widgets).slice(:widget_a, :widget_c)
345
+ end
346
+ end
347
+ end
312
348
  end
@@ -3,8 +3,6 @@ require 'kookaburra'
3
3
  describe Kookaburra do
4
4
  describe '#given' do
5
5
  it 'returns an instance of the configured GivenDriver' do
6
- browser_instance = stub('Browser', :app => :a_rack_app)
7
-
8
6
  Kookaburra::RackDriver.should_receive(:new) \
9
7
  .with(:a_rack_app) \
10
8
  .and_return(:a_rack_driver)
@@ -22,7 +20,7 @@ describe Kookaburra do
22
20
 
23
21
  k = Kookaburra.new(:given_driver_class => my_given_driver_class,
24
22
  :api_driver_class => my_api_driver_class,
25
- :browser => browser_instance)
23
+ :rack_app => :a_rack_app)
26
24
  k.given.should == :a_given_driver
27
25
  end
28
26
  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: 89
4
+ hash: 87
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 17
9
- - 1
10
- version: 0.17.1
8
+ - 18
9
+ - 0
10
+ version: 0.18.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Wilger
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2012-03-17 00:00:00 Z
20
+ date: 2012-03-18 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  version_requirements: &id001 !ruby/object:Gem::Requirement
@@ -29,12 +29,26 @@ dependencies:
29
29
  segments:
30
30
  - 0
31
31
  version: "0"
32
- name: i18n
32
+ name: basic_object
33
33
  prerelease: false
34
34
  type: :runtime
35
35
  requirement: *id001
36
36
  - !ruby/object:Gem::Dependency
37
37
  version_requirements: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ name: i18n
47
+ prerelease: false
48
+ type: :runtime
49
+ requirement: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ version_requirements: &id003 !ruby/object:Gem::Requirement
38
52
  none: false
39
53
  requirements:
40
54
  - - ">="
@@ -47,9 +61,9 @@ dependencies:
47
61
  name: activesupport
48
62
  prerelease: false
49
63
  type: :runtime
50
- requirement: *id002
64
+ requirement: *id003
51
65
  - !ruby/object:Gem::Dependency
52
- version_requirements: &id003 !ruby/object:Gem::Requirement
66
+ version_requirements: &id004 !ruby/object:Gem::Requirement
53
67
  none: false
54
68
  requirements:
55
69
  - - ">="
@@ -61,9 +75,9 @@ dependencies:
61
75
  name: rack-test
62
76
  prerelease: false
63
77
  type: :runtime
64
- requirement: *id003
78
+ requirement: *id004
65
79
  - !ruby/object:Gem::Dependency
66
- version_requirements: &id004 !ruby/object:Gem::Requirement
80
+ version_requirements: &id005 !ruby/object:Gem::Requirement
67
81
  none: false
68
82
  requirements:
69
83
  - - ">="
@@ -75,9 +89,9 @@ dependencies:
75
89
  name: rspec
76
90
  prerelease: false
77
91
  type: :development
78
- requirement: *id004
92
+ requirement: *id005
79
93
  - !ruby/object:Gem::Dependency
80
- version_requirements: &id005 !ruby/object:Gem::Requirement
94
+ version_requirements: &id006 !ruby/object:Gem::Requirement
81
95
  none: false
82
96
  requirements:
83
97
  - - ">="
@@ -89,9 +103,9 @@ dependencies:
89
103
  name: capybara
90
104
  prerelease: false
91
105
  type: :development
92
- requirement: *id005
106
+ requirement: *id006
93
107
  - !ruby/object:Gem::Dependency
94
- version_requirements: &id006 !ruby/object:Gem::Requirement
108
+ version_requirements: &id007 !ruby/object:Gem::Requirement
95
109
  none: false
96
110
  requirements:
97
111
  - - ">="
@@ -103,9 +117,9 @@ dependencies:
103
117
  name: yard
104
118
  prerelease: false
105
119
  type: :development
106
- requirement: *id006
120
+ requirement: *id007
107
121
  - !ruby/object:Gem::Dependency
108
- version_requirements: &id007 !ruby/object:Gem::Requirement
122
+ version_requirements: &id008 !ruby/object:Gem::Requirement
109
123
  none: false
110
124
  requirements:
111
125
  - - ~>
@@ -118,9 +132,9 @@ dependencies:
118
132
  name: redcarpet
119
133
  prerelease: false
120
134
  type: :development
121
- requirement: *id007
135
+ requirement: *id008
122
136
  - !ruby/object:Gem::Dependency
123
- version_requirements: &id008 !ruby/object:Gem::Requirement
137
+ version_requirements: &id009 !ruby/object:Gem::Requirement
124
138
  none: false
125
139
  requirements:
126
140
  - - ">="
@@ -132,9 +146,9 @@ dependencies:
132
146
  name: jeweler
133
147
  prerelease: false
134
148
  type: :development
135
- requirement: *id008
149
+ requirement: *id009
136
150
  - !ruby/object:Gem::Dependency
137
- version_requirements: &id009 !ruby/object:Gem::Requirement
151
+ version_requirements: &id010 !ruby/object:Gem::Requirement
138
152
  none: false
139
153
  requirements:
140
154
  - - ">="
@@ -146,9 +160,9 @@ dependencies:
146
160
  name: rcov
147
161
  prerelease: false
148
162
  type: :development
149
- requirement: *id009
163
+ requirement: *id010
150
164
  - !ruby/object:Gem::Dependency
151
- version_requirements: &id010 !ruby/object:Gem::Requirement
165
+ version_requirements: &id011 !ruby/object:Gem::Requirement
152
166
  none: false
153
167
  requirements:
154
168
  - - ">="
@@ -160,9 +174,9 @@ dependencies:
160
174
  name: reek
161
175
  prerelease: false
162
176
  type: :development
163
- requirement: *id010
177
+ requirement: *id011
164
178
  - !ruby/object:Gem::Dependency
165
- version_requirements: &id011 !ruby/object:Gem::Requirement
179
+ version_requirements: &id012 !ruby/object:Gem::Requirement
166
180
  none: false
167
181
  requirements:
168
182
  - - ">="
@@ -174,7 +188,7 @@ dependencies:
174
188
  name: sinatra
175
189
  prerelease: false
176
190
  type: :development
177
- requirement: *id011
191
+ requirement: *id012
178
192
  description: Cucumber + Capybara = Kookaburra? It made sense at the time.
179
193
  email: johnwilger@gmail.com
180
194
  executables: []
@@ -202,6 +216,7 @@ files:
202
216
  - lib/kookaburra/exceptions.rb
203
217
  - lib/kookaburra/given_driver.rb
204
218
  - lib/kookaburra/json_api_driver.rb
219
+ - lib/kookaburra/null_browser.rb
205
220
  - lib/kookaburra/rack_driver.rb
206
221
  - lib/kookaburra/test_data.rb
207
222
  - lib/kookaburra/test_helpers.rb
@@ -209,6 +224,7 @@ files:
209
224
  - lib/kookaburra/ui_driver/ui_component.rb
210
225
  - lib/kookaburra/utils/active_record_shared_connection.rb
211
226
  - spec/kookaburra/json_api_driver_spec.rb
227
+ - spec/kookaburra/null_browser_spec.rb
212
228
  - spec/kookaburra/rack_driver_spec.rb
213
229
  - spec/kookaburra/test_data_spec.rb
214
230
  - spec/kookaburra/test_helpers_spec.rb