kookaburra 0.16.1 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -20,7 +20,7 @@ Jeweler::Tasks.new do |gem|
20
20
  gem.summary = %Q{WindowDriver testing pattern for Ruby apps}
21
21
  gem.description = %Q{Cucumber + Capybara = Kookaburra? It made sense at the time.}
22
22
  gem.email = "johnwilger@gmail.com"
23
- gem.authors = ["John Wilger", "Sam Livingston-Gray"]
23
+ gem.authors = ["John Wilger", "Sam Livingston-Gray", "Ravi Gadad"]
24
24
  # dependencies defined in Gemfile
25
25
  end
26
26
  Jeweler::RubygemsDotOrgTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.16.1
1
+ 0.17.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.16.1"
8
+ s.version = "0.17.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["John Wilger", "Sam Livingston-Gray"]
12
- s.date = "2012-03-15"
11
+ s.authors = ["John Wilger", "Sam Livingston-Gray", "Ravi Gadad"]
12
+ s.date = "2012-03-16"
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 = [
@@ -65,12 +65,26 @@ class Kookaburra
65
65
  # api.create_widget(:name => 'Foo')
66
66
  # #=> {:id => 1, :name => 'Foo', :description => ''}
67
67
  def post(path, data)
68
+ do_json_request(:post, path, data)
69
+ end
70
+
71
+ def put(path, data)
72
+ do_json_request(:put, path, data)
73
+ end
74
+
75
+ def get(path, data)
76
+ do_json_request(:get, path, data)
77
+ end
78
+
79
+ private
80
+
81
+ def do_json_request(method, path, data)
68
82
  json_request_headers = {
69
83
  'Content-Type' => 'application/json',
70
84
  'Accept' => 'application/json'
71
85
  }
72
- response = @app_driver.post(path, J.encode(data), json_request_headers)
73
- J.decode(response).symbolize_keys
86
+ response = @app_driver.send(method.to_sym, path, J.encode(data), json_request_headers)
87
+ J.decode(response)
74
88
  end
75
89
  end
76
90
  end
@@ -37,6 +37,50 @@ class Kookaburra
37
37
  last_response.body
38
38
  end
39
39
 
40
+ # Sends a PUT request to the application.
41
+ #
42
+ # Similar to `Rack::Test::Methods#put` except that it adds more convenient
43
+ # access to setting request headers, it raises an exception if the response
44
+ # status is not 200, and it returns the response body.
45
+ #
46
+ # @param [String] path The path portion of the URI to request from the
47
+ # application
48
+ # @param [Object] params The request params or body
49
+ # @param [Hash] headers A hash of any additional HTTP headers to be set on
50
+ # the request.
51
+ # @param [Hash] env Additional environment variables that should be present
52
+ # on the request.
53
+ # @yield [Rack::Response] Yields the last response to the block if a
54
+ # block is given.
55
+ def put(path, params = {}, headers = {}, env = {}, &block)
56
+ set_headers(headers)
57
+ super path, params, env, &block
58
+ check_response_status!(:put, 200, path)
59
+ last_response.body
60
+ end
61
+
62
+ # Sends a GET request to the application.
63
+ #
64
+ # Similar to `Rack::Test::Methods#get` except that it adds more convenient
65
+ # access to setting request headers, it raises an exception if the response
66
+ # status is not 200, and it returns the response body.
67
+ #
68
+ # @param [String] path The path portion of the URI to request from the
69
+ # application
70
+ # @param [Object] params The request params or body
71
+ # @param [Hash] headers A hash of any additional HTTP headers to be set on
72
+ # the request.
73
+ # @param [Hash] env Additional environment variables that should be present
74
+ # on the request.
75
+ # @yield [Rack::Response] Yields the last response to the block if a
76
+ # block is given.
77
+ def get(path, params = {}, headers = {}, env = {}, &block)
78
+ set_headers(headers)
79
+ super path, params, env, &block
80
+ check_response_status!(:get, 200, path)
81
+ last_response.body
82
+ end
83
+
40
84
  private
41
85
 
42
86
  def check_response_status!(verb, expected_status, path)
@@ -1,24 +1,26 @@
1
1
  require 'kookaburra/json_api_driver'
2
2
 
3
3
  describe Kookaburra::JsonApiDriver do
4
- describe 'private methods (for use by subclasses)' do
5
- describe '#post' do
6
- it 'posts data as JSON to the specified path within the application' do
7
- app_driver = mock('RackDriver')
8
- app_driver.should_receive(:post) \
9
- .with('/foo', '{"bar":"baz"}',
10
- 'Content-Type' => 'application/json',
11
- 'Accept' => 'application/json') \
12
- .and_return('{"foo":"bar"}')
13
- driver = Kookaburra::JsonApiDriver.new(app_driver)
14
- driver.send(:post, '/foo', {:bar => :baz})
15
- end
4
+ describe 'protected methods (for use by subclasses)' do
5
+ ['post', 'put', 'get'].each do |method|
6
+ describe "##{method}" do
7
+ it "sends a #{method} request with JSON data to the specified path within the application" do
8
+ app_driver = mock('RackDriver')
9
+ app_driver.should_receive(method.to_sym) \
10
+ .with('/foo', '{"bar":"baz"}',
11
+ 'Content-Type' => 'application/json',
12
+ 'Accept' => 'application/json') \
13
+ .and_return('{"foo":"bar"}')
14
+ driver = Kookaburra::JsonApiDriver.new(app_driver)
15
+ driver.send(method.to_sym, '/foo', {:bar => :baz})
16
+ end
16
17
 
17
- it 'returns the response body parsed from JSON' do
18
- app_driver = stub('RackDriver', :post => '{"ham":"spam"}')
19
- driver = Kookaburra::JsonApiDriver.new(app_driver)
20
- driver.send(:post, '/foo', {:bar => :baz}) \
21
- .should == {:ham => 'spam'}
18
+ it 'returns the response body parsed from JSON' do
19
+ app_driver = stub('RackDriver', method.to_sym => '{"ham":"spam"}')
20
+ driver = Kookaburra::JsonApiDriver.new(app_driver)
21
+ driver.send(method.to_sym, '/foo', {:bar => :baz}) \
22
+ .should == {'ham' => 'spam'}
23
+ end
22
24
  end
23
25
  end
24
26
 
@@ -5,32 +5,38 @@ describe Kookaburra::RackDriver do
5
5
  Kookaburra::RackDriver.should include(Rack::Test::Methods)
6
6
  end
7
7
 
8
- describe '#post' do
9
- it 'returns the response body' do
10
- app = stub('Rack App', :call => [201, {}, 'response body'])
11
- driver = Kookaburra::RackDriver.new(app)
12
- driver.post('/foo', 'req body').should == 'response body'
13
- end
8
+ {
9
+ 'post' => {:success => 201, :unexpected => 200},
10
+ 'put' => {:success => 200, :unexpected => 404},
11
+ 'get' => {:success => 200, :unexpected => 404}
12
+ }.each_pair do |method, codes|
13
+ describe "##{method}" do
14
+ it 'returns the response body' do
15
+ app = stub('Rack App', :call => [codes[:success], {}, 'response body'])
16
+ driver = Kookaburra::RackDriver.new(app)
17
+ driver.send(method.to_sym, '/foo', 'req body').should == 'response body'
18
+ end
14
19
 
15
- it 'sets the specified headers on the request' do
16
- app = mock('Rack App')
17
- driver = Kookaburra::RackDriver.new(app)
18
- app.should_receive(:call) do |env|
19
- env['HTTP_HEADER_A'].should == 'foo'
20
- env['HTTP_HEADER_B'].should == 'bar'
21
- [201, {}, 'foo']
20
+ it 'sets the specified headers on the request' do
21
+ app = mock('Rack App')
22
+ driver = Kookaburra::RackDriver.new(app)
23
+ app.should_receive(:call) do |env|
24
+ env['HTTP_HEADER_A'].should == 'foo'
25
+ env['HTTP_HEADER_B'].should == 'bar'
26
+ [codes[:success], {}, 'foo']
27
+ end
28
+ driver.send(method.to_sym, '/foo', 'req body', 'header-a' => 'foo', 'header-b' => 'bar')
22
29
  end
23
- driver.post('/foo', 'req body', 'header-a' => 'foo', 'header-b' => 'bar')
24
- end
25
30
 
26
- it 'raises a Kookabura::UnexpectedResponse if response status is not 201' do
27
- app_response = [200, {'Content-Type' => 'application/json'}, 'Here is the response body']
28
- app = stub('Rack App', :call => app_response)
29
- driver = Kookaburra::RackDriver.new(app)
30
- lambda { driver.send(:post, '/foo', {:bar => :baz}) } \
31
- .should raise_error(Kookaburra::UnexpectedResponse,
32
- "post to /foo unexpectedly responded with an HTTP status of 200:\n" \
33
- + 'Here is the response body')
31
+ it "raises a Kookabura::UnexpectedResponse if response status is not #{codes[:success]}" do
32
+ app_response = [codes[:unexpected], {'Content-Type' => 'application/json'}, 'Here is the response body']
33
+ app = stub('Rack App', :call => app_response)
34
+ driver = Kookaburra::RackDriver.new(app)
35
+ lambda { driver.send(method, '/foo', {:bar => :baz}) } \
36
+ .should raise_error(Kookaburra::UnexpectedResponse,
37
+ "#{method} to /foo unexpectedly responded with an HTTP status of #{codes[:unexpected]}:\n" \
38
+ + 'Here is the response body')
39
+ end
34
40
  end
35
41
  end
36
42
  end
@@ -20,13 +20,13 @@ describe 'Kookaburra Integration' do
20
20
 
21
21
  class MyGivenDriver < Kookaburra::GivenDriver
22
22
  def a_user(name)
23
- user = {:email => 'bob@example.com', :password => '12345'}
23
+ user = {'email' => 'bob@example.com', 'password' => '12345'}
24
24
  result = api.create_user(user)
25
25
  test_data.users[name] = result
26
26
  end
27
27
 
28
28
  def a_widget(name, attributes = {})
29
- widget = {:name => 'Foo'}.merge(attributes)
29
+ widget = {'name' => 'Foo'}.merge(attributes)
30
30
  result = api.create_widget(widget)
31
31
  test_data.widgets[name] = result
32
32
  end
@@ -42,8 +42,8 @@ describe 'Kookaburra Integration' do
42
42
  end
43
43
 
44
44
  def sign_in(user_data)
45
- fill_in 'Email:', :with => user_data[:email]
46
- fill_in 'Password:', :with => user_data[:password]
45
+ fill_in 'Email:', :with => user_data['email']
46
+ fill_in 'Password:', :with => user_data['password']
47
47
  click_button 'Sign In'
48
48
  end
49
49
  end
@@ -73,15 +73,15 @@ describe 'Kookaburra Integration' do
73
73
  end
74
74
 
75
75
  def choose_to_delete_widget(widget_data)
76
- find("#delete_#{widget_data[:id]}").click_button('Delete')
76
+ find("#delete_#{widget_data['id']}").click_button('Delete')
77
77
  end
78
78
 
79
79
  private
80
80
 
81
81
  def extract_widget_data(element)
82
82
  {
83
- :id => element.find('.id').text,
84
- :name => element.find('.name').text
83
+ 'id' => element.find('.id').text,
84
+ 'name' => element.find('.name').text
85
85
  }
86
86
  end
87
87
  end
@@ -92,7 +92,7 @@ describe 'Kookaburra Integration' do
92
92
  end
93
93
 
94
94
  def submit(widget_data)
95
- fill_in 'Name:', :with => widget_data[:name]
95
+ fill_in 'Name:', :with => widget_data['name']
96
96
  click_on 'Save'
97
97
  end
98
98
  end
@@ -110,7 +110,7 @@ describe 'Kookaburra Integration' do
110
110
  def create_new_widget(name, attributes = {})
111
111
  widget_list.show
112
112
  widget_list.choose_to_create_new_widget
113
- widget_form.submit(:name => 'My Widget')
113
+ widget_form.submit('name' => 'My Widget')
114
114
  test_data.widgets[name] = widget_list.last_widget_created
115
115
  end
116
116
 
metadata CHANGED
@@ -1,22 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kookaburra
3
3
  version: !ruby/object:Gem::Version
4
- hash: 93
4
+ hash: 91
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 16
9
- - 1
10
- version: 0.16.1
8
+ - 17
9
+ - 0
10
+ version: 0.17.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Wilger
14
14
  - Sam Livingston-Gray
15
+ - Ravi Gadad
15
16
  autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2012-03-15 00:00:00 Z
20
+ date: 2012-03-16 00:00:00 Z
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
22
23
  version_requirements: &id001 !ruby/object:Gem::Requirement