kookaburra 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.7.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.6.0"
8
+ s.version = "0.7.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"]
12
- s.date = "2012-01-18"
12
+ s.date = "2012-01-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 = [
@@ -37,6 +37,7 @@ Gem::Specification.new do |s|
37
37
  "lib/kookaburra/ui_driver/mixins/has_ui_component.rb",
38
38
  "lib/kookaburra/ui_driver/ui_component.rb",
39
39
  "test/helper.rb",
40
+ "test/kookaburra/test_data_test.rb",
40
41
  "test/kookaburra/ui_driver_test.rb",
41
42
  "test/kookaburra_test.rb"
42
43
  ]
@@ -1,9 +1,12 @@
1
1
  require 'active_support/hash_with_indifferent_access'
2
+ require 'active_support/core_ext/hash'
2
3
 
3
4
  # This is the mechanism for sharing state between Cucumber steps.
4
5
  # If you're using instance variables, YOU'RE DOING IT WRONG.
5
6
  module Kookaburra
6
7
  class TestData
8
+ Defaults = HashWithIndifferentAccess.new
9
+
7
10
  def initialize
8
11
  @data = Hash.new do |hash, key|
9
12
  hash[key] = Hash.new { |hash, key| hash[key] = HashWithIndifferentAccess.new }
@@ -13,20 +16,24 @@ module Kookaburra
13
16
  def __collection(collection_key)
14
17
  @data[collection_key]
15
18
  end
19
+
16
20
  def __fetch_data(collection_key, value_key)
17
21
  __collection(collection_key).fetch(value_key)
18
22
  rescue IndexError => e
19
23
  raise e.exception("Key #{value_key.inspect} not found in #{collection_key}")
20
24
  end
25
+
21
26
  def __get_data(collection_key, value_key)
22
27
  __collection(collection_key)[value_key]
23
28
  end
29
+
24
30
  def __set_data(collection_key, value_key, value_hash = {})
25
31
  __collection(collection_key)[value_key] = HashWithIndifferentAccess.new(value_hash)
26
32
  end
27
33
 
28
- def self.provide_collection(name)
29
- class_eval <<-RUBY
34
+ class << self
35
+ def provide_collection(name)
36
+ class_eval <<-RUBY
30
37
  def #{name}(key = :default)
31
38
  __get_data(:#{name}, key)
32
39
  end
@@ -36,14 +43,20 @@ module Kookaburra
36
43
  def set_#{name}(key, value_hash = {})
37
44
  __set_data(:#{name}, key, value_hash)
38
45
  end
39
- RUBY
46
+ RUBY
47
+ end
48
+
49
+ def set_default(key, value)
50
+ Kookaburra::TestData::Defaults[key] = value
51
+ end
52
+
53
+ def default(key)
54
+ Defaults[key]
55
+ end
40
56
  end
41
57
 
42
- Defaults = HashWithIndifferentAccess.new
43
58
  def default(key)
44
- # NOTE: Marshal seems clunky, but gives us a deep copy.
45
- # This keeps mutations from being preserved between test runs.
46
- ( @default ||= Marshal::load(Marshal.dump(Defaults)) )[key]
59
+ (@defaults ||= Defaults.deep_dup)[key]
47
60
  end
48
61
  end
49
62
  end
data/lib/kookaburra.rb CHANGED
@@ -83,12 +83,8 @@ module Kookaburra
83
83
  @ui_driver ||= Kookaburra::UIDriver
84
84
  end
85
85
 
86
- # The TestData class that will be used by Kookaburra, typically a subclass of
87
- # Kookaburra::TestData.
88
- attr_accessor :test_data
89
-
90
- def test_data
91
- @test_data ||= Kookaburra::TestData
86
+ def test_data_setup(&blk)
87
+ Kookaburra::TestData.class_eval(&blk)
92
88
  end
93
89
  end
94
90
 
@@ -146,7 +142,7 @@ module Kookaburra
146
142
  # The Kookaburra::TestData instance should not be used directly, but all of
147
143
  # the drivers should reference the same instance.
148
144
  def kookaburra_test_data
149
- kookaburra_drivers[:test_data] ||= Kookaburra.test_data.new
145
+ kookaburra_drivers[:test_data] ||= Kookaburra::TestData.new
150
146
  end
151
147
 
152
148
  # Holds references to all drivers in a single hash, so that
@@ -0,0 +1,21 @@
1
+ require 'helper'
2
+
3
+ describe Kookaburra::TestData do
4
+ describe '.set_default' do
5
+ it 'stores data that can be used as defaults for tests' do
6
+ Kookaburra::TestData.set_default(:foo, 'bar')
7
+ td = Kookaburra::TestData.new
8
+ assert_equal 'bar', Kookaburra::TestData.default(:foo)
9
+ end
10
+ end
11
+
12
+ describe '#default' do
13
+ it 'does not allow default to change between instances' do
14
+ Kookaburra::TestData.set_default(:foo, 'bar' => 'baz')
15
+ td1 = Kookaburra::TestData.new
16
+ td1.default(:foo)['bar'] = 'spam'
17
+ td2 = Kookaburra::TestData.new
18
+ assert_equal 'baz', td2.default(:foo)['bar']
19
+ end
20
+ end
21
+ end
@@ -31,6 +31,7 @@ describe Kookaburra::UIDriver do
31
31
  attr_reader :was_shown, :params
32
32
  end
33
33
 
34
+ let(:ui) { ui_class.new }
34
35
  let(:ui_class) do
35
36
  Class.new(Kookaburra::UIDriver) do
36
37
  def browser; end
@@ -41,13 +42,11 @@ describe Kookaburra::UIDriver do
41
42
  end
42
43
 
43
44
  it 'delegates to the UIComponent#show! method' do
44
- ui = ui_class.new
45
45
  ui.navigate_to :foo
46
46
  assert Foo.was_shown, "#show! was never called on the Foo component"
47
47
  end
48
48
 
49
49
  it 'passed any additional options to the UIComponent#show! method' do
50
- ui = ui_class.new
51
50
  ui.navigate_to :foo, :bar => :baz
52
51
  assert_equal({:bar => :baz}, Foo.params)
53
52
  end
@@ -169,15 +169,15 @@ describe Kookaburra do
169
169
  end
170
170
  end
171
171
 
172
- describe '#test_data' do
173
- it 'is a read/write attribute' do
174
- Kookaburra.test_data = :a_test_data
175
- assert_equal :a_test_data, Kookaburra.test_data
176
- end
177
-
178
- it 'defaults to Kookaburra::TestData' do
179
- Kookaburra.test_data = nil
180
- assert_equal Kookaburra::TestData, Kookaburra.test_data
172
+ describe '.test_data_setup' do
173
+ it 'evaluates the block in the context of the TestData class' do
174
+ Kookaburra.test_data_setup do
175
+ def added_by_a_test
176
+ :added_by_a_test
177
+ end
178
+ end
179
+ td = Kookaburra::TestData.new
180
+ assert_equal :added_by_a_test, td.added_by_a_test
181
181
  end
182
182
  end
183
183
  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: 7
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 6
8
+ - 7
9
9
  - 0
10
- version: 0.6.0
10
+ version: 0.7.0
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-01-18 00:00:00 Z
18
+ date: 2012-01-22 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement
@@ -182,6 +182,7 @@ files:
182
182
  - lib/kookaburra/ui_driver/mixins/has_ui_component.rb
183
183
  - lib/kookaburra/ui_driver/ui_component.rb
184
184
  - test/helper.rb
185
+ - test/kookaburra/test_data_test.rb
185
186
  - test/kookaburra/ui_driver_test.rb
186
187
  - test/kookaburra_test.rb
187
188
  homepage: http://github.com/projectdx/kookaburra