lookout-rack-test 1.0.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.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +70 -0
- data/Rakefile +4 -0
- data/cucumber.yml +5 -0
- data/examples/test_app.rb +62 -0
- data/examples/test_models.rb +15 -0
- data/features/general_steps/requests.feature +13 -0
- data/features/general_steps/requests_with_json_body.feature +15 -0
- data/features/general_steps/requests_with_params.feature +27 -0
- data/features/general_steps/response.feature +21 -0
- data/features/liquid_templates.feature +44 -0
- data/features/not_timefreeze.feature +14 -0
- data/features/number_transform.feature +5 -0
- data/features/step_definitions/liquid_templates_steps.rb +3 -0
- data/features/step_definitions/number_transform_steps.rb +7 -0
- data/features/step_definitions/timefreeze_steps.rb +15 -0
- data/features/support/env.rb +10 -0
- data/features/timefreeze.feature +15 -0
- data/lib/lookout/rack/test.rb +8 -0
- data/lib/lookout/rack/test/cucumber.rb +32 -0
- data/lib/lookout/rack/test/cucumber/before.rb +5 -0
- data/lib/lookout/rack/test/cucumber/general_steps.rb +42 -0
- data/lib/lookout/rack/test/cucumber/server.rb +11 -0
- data/lib/lookout/rack/test/cucumber/transforms.rb +3 -0
- data/lib/lookout/rack/test/load_factories.rb +5 -0
- data/lib/lookout/rack/test/rake.rb +16 -0
- data/lib/lookout/rack/test/rake/cucumber.rake +16 -0
- data/lib/lookout/rack/test/rake/rspec.rake +21 -0
- data/lib/lookout/rack/test/rspec.rb +52 -0
- data/lib/lookout/rack/test/rspec/email_helpers.rb +32 -0
- data/lib/lookout/rack/test/rspec/fake_request.rb +20 -0
- data/lib/lookout/rack/test/rspec/model_examples.rb +12 -0
- data/lib/lookout/rack/test/rspec/route_helper.rb +7 -0
- data/lib/lookout/rack/test/version.rb +7 -0
- data/lookout-rack-test.gemspec +44 -0
- data/spec/email_helpers_spec.rb +104 -0
- data/spec/model_examples_spec.rb +51 -0
- data/spec/setup_spec.rb +51 -0
- data/spec/spec_helper.rb +15 -0
- metadata +339 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OTEwMDdiNzc5NjU3NDJhYTU0NzUyNzhhNzkyNTBmNzM0OGRlYWRiOA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZmQxM2NlM2NhYmYwMDUyMzFlMzg0Yjk5MWIwY2E3NTE3N2I5YzUyOA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MTUxNzg0MWU5M2Q4ODFkNDg1OWIwZjBmMTdjMjU1NzczMmM5YjNlZjQzMTZi
|
10
|
+
MzBjNzRlNDIwYzc3YmNkMTFkNzhmN2YxZjRlMjk2MjZlNGE5MDZiNjE3MmY0
|
11
|
+
YzZhMjE3MjRmZDZmM2Y2NjYxMTBmNmIxYWMwMTlhODdkMmM2Y2M=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MTFjZjc2ZjVmNDFjMTVhM2UxYWU3YWZhZjkyYzI3YmUzY2VmYTliYTg4MjBk
|
14
|
+
YzkwNDNlYzBlNmFkZDY4YzQ4NWVjY2Q1OTJkN2EwZjU2YTViZTNhY2JiNDMx
|
15
|
+
NTA2MmU3N2NjMWI4YjM0ZThlOGNhODBmMTQyNzgwMjJmMzljMTg=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Lookout, Inc
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Lookout::Rack::Test
|
2
|
+
|
3
|
+
RSpec and Cucumber test helpers.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'lookout-rack-test'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install lookout-rack-test
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
`Lookout::Rack::Test` is intended to be consumed in pieces; it falls into three
|
22
|
+
modules, `RSpec`, `Cucumber`, and `Rake`.
|
23
|
+
|
24
|
+
### RSpec
|
25
|
+
See examples in `spec/`. `Lookout::Rack::Test::RSpec::FakeRequest` may also be
|
26
|
+
helpful, if you want to test helper modules that are intended to be mixed into a
|
27
|
+
route environment.
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
module Lookout::Rack::Test::RSpec
|
31
|
+
class FakeRequest
|
32
|
+
# Reopen the class to add a helper
|
33
|
+
include My::Helper
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe My::Helper do
|
38
|
+
let(:helper) { Lookout::Rack::Test::RSpec::FakeRequest.new }
|
39
|
+
|
40
|
+
# ... etc
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
### Cucumber
|
45
|
+
See examples in `features/`.
|
46
|
+
|
47
|
+
### Rake tasks
|
48
|
+
`require 'lookout/rack/test/rake' in your Rakefile to pick up the RSpec and
|
49
|
+
Cucumber test tasks, namespaced under `:spec` and `:cucumber` respectively.
|
50
|
+
|
51
|
+
Note that the `:cucumber` tasks require a `cucumber.yml`, e.g.:
|
52
|
+
|
53
|
+
```yml
|
54
|
+
<%
|
55
|
+
standard = "--expand -r features --format pretty --format junit --out features/reports"
|
56
|
+
browser_opts = "--tags @selenium"
|
57
|
+
%>
|
58
|
+
|
59
|
+
default: <%= standard %> <%= browser_opts %> --tags ~@wip --tags ~@api
|
60
|
+
wip: <%= standard %> --tags @wip
|
61
|
+
api: <%= standard %> --tags @api --tags ~@wip
|
62
|
+
```
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
1. Fork it
|
67
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
68
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
69
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
70
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/cucumber.yml
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class TestApp < Sinatra::Application
|
5
|
+
get '/' do
|
6
|
+
status 200
|
7
|
+
end
|
8
|
+
|
9
|
+
post '/' do
|
10
|
+
response = { 'some_param' => params['some_param'],
|
11
|
+
'im_a_number' => params['im_a_number'] }
|
12
|
+
status 201
|
13
|
+
|
14
|
+
return response.to_json
|
15
|
+
end
|
16
|
+
|
17
|
+
put '/' do
|
18
|
+
response = { 'some_param' => params['some_param'],
|
19
|
+
'im_a_number' => params['im_a_number'] }
|
20
|
+
status 202
|
21
|
+
|
22
|
+
return response.to_json
|
23
|
+
end
|
24
|
+
|
25
|
+
get '/json' do
|
26
|
+
return { 'key' => 1 }.to_json
|
27
|
+
end
|
28
|
+
|
29
|
+
post '/json' do
|
30
|
+
request.body.rewind
|
31
|
+
body = JSON.parse(request.body.read)
|
32
|
+
|
33
|
+
status 201
|
34
|
+
return body.to_json
|
35
|
+
end
|
36
|
+
|
37
|
+
delete '/json' do
|
38
|
+
request.body.rewind
|
39
|
+
body = JSON.parse(request.body.read)
|
40
|
+
|
41
|
+
if body['some_key'] == 'some_value'
|
42
|
+
status 203
|
43
|
+
else
|
44
|
+
halt 400
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
get '/redirect' do
|
49
|
+
redirect to '/'
|
50
|
+
end
|
51
|
+
|
52
|
+
# For testing Timefreeze in Cukes
|
53
|
+
get '/time' do
|
54
|
+
time = Time.now.to_i
|
55
|
+
|
56
|
+
return { 'time' => time }.to_json
|
57
|
+
end
|
58
|
+
|
59
|
+
get '/route/:uri_var' do |uri_var|
|
60
|
+
return { 'variable' => uri_var }.to_json
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Feature: Requests with no body or params
|
2
|
+
|
3
|
+
Scenario: I should be able to GET a route, and check the response status
|
4
|
+
When I GET "/"
|
5
|
+
Then the response should be 200
|
6
|
+
|
7
|
+
Scenario: I should be able to POST to a route, and check the response status
|
8
|
+
When I POST to "/"
|
9
|
+
Then the response should be 201
|
10
|
+
|
11
|
+
Scenario: I should be able to PUT to a route, and check the response status
|
12
|
+
When I PUT to "/"
|
13
|
+
Then the response should be 202
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Feature: Requests with JSON body
|
2
|
+
|
3
|
+
Scenario: POST with JSON body
|
4
|
+
When I POST to "/json" with the JSON:
|
5
|
+
"""
|
6
|
+
{ "some_key" : "some_value" }
|
7
|
+
"""
|
8
|
+
Then the response should be 201
|
9
|
+
|
10
|
+
Scenario: DELETE with JSON body
|
11
|
+
When I DELETE to "/json" with the JSON:
|
12
|
+
"""
|
13
|
+
{ "some_key" : "some_value" }
|
14
|
+
"""
|
15
|
+
Then the response should be 203
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Feature: Requests with params, JSON response
|
2
|
+
|
3
|
+
Scenario: POST with params
|
4
|
+
When I POST to "/" with:
|
5
|
+
| Name | Value |
|
6
|
+
| some_param | some_value |
|
7
|
+
| im_a_number | 1 |
|
8
|
+
Then the response should be 201
|
9
|
+
And I should receive the JSON:
|
10
|
+
"""
|
11
|
+
{ "some_param" : "some_value",
|
12
|
+
"im_a_number" : "1"
|
13
|
+
}
|
14
|
+
"""
|
15
|
+
|
16
|
+
Scenario: PUT with params
|
17
|
+
When I PUT to "/" with:
|
18
|
+
| Name | Value |
|
19
|
+
| some_param | some_value |
|
20
|
+
| im_a_number | 1 |
|
21
|
+
Then the response should be 202
|
22
|
+
And I should receive the JSON:
|
23
|
+
"""
|
24
|
+
{ "some_param" : "some_value",
|
25
|
+
"im_a_number" : "1"
|
26
|
+
}
|
27
|
+
"""
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Feature: Responses
|
2
|
+
|
3
|
+
Scenario: Normal response
|
4
|
+
When I GET "/"
|
5
|
+
Then the response should be 200
|
6
|
+
|
7
|
+
Scenario: Response with JSON body
|
8
|
+
When I GET "/json"
|
9
|
+
Then the response should be 200
|
10
|
+
And I should receive the JSON:
|
11
|
+
"""
|
12
|
+
{ "key" : 1 }
|
13
|
+
"""
|
14
|
+
|
15
|
+
Scenario: Not found response
|
16
|
+
When I GET "/no_such_route"
|
17
|
+
Then the response should be 404
|
18
|
+
|
19
|
+
Scenario: Redirect
|
20
|
+
When I GET "/redirect"
|
21
|
+
Then I should be redirected to "/"
|
@@ -0,0 +1,44 @@
|
|
1
|
+
Feature: Liquid templates
|
2
|
+
"""
|
3
|
+
Note that these also show variable interpolation happening in the response body
|
4
|
+
"""
|
5
|
+
|
6
|
+
Scenario: Variable interpolation in URI
|
7
|
+
When I have set some template variable "foo"
|
8
|
+
And I GET "/route/{{foo}}"
|
9
|
+
Then the response should be 200
|
10
|
+
And I should receive the JSON:
|
11
|
+
"""
|
12
|
+
{ "variable" : "{{foo}}" }
|
13
|
+
"""
|
14
|
+
|
15
|
+
Scenario: Variable interpolation in params
|
16
|
+
When I have set some template variable "foo"
|
17
|
+
And I POST to "/" with:
|
18
|
+
| Name | Value |
|
19
|
+
| some_param | {{foo}} |
|
20
|
+
| im_a_number | 1 |
|
21
|
+
Then the response should be 201
|
22
|
+
And I should receive the JSON:
|
23
|
+
"""
|
24
|
+
{
|
25
|
+
"some_param" : "{{foo}}",
|
26
|
+
"im_a_number" : "1"
|
27
|
+
}
|
28
|
+
"""
|
29
|
+
|
30
|
+
Scenario: Variable interpolation in JSON body
|
31
|
+
When I have set some template variable "foo"
|
32
|
+
And I POST to "/json" with the JSON:
|
33
|
+
"""
|
34
|
+
{
|
35
|
+
"some_var" : "{{foo}}"
|
36
|
+
}
|
37
|
+
"""
|
38
|
+
Then the response should be 201
|
39
|
+
And I should receive the JSON:
|
40
|
+
"""
|
41
|
+
{
|
42
|
+
"some_var" : "{{foo}}"
|
43
|
+
}
|
44
|
+
"""
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Feature: Timefreeze and liquid templates
|
2
|
+
"""
|
3
|
+
This test does not happen in frozen time because it is not tagged @timefreeze - it is here to serve as a contrast to timefreeze.feature
|
4
|
+
"""
|
5
|
+
|
6
|
+
Scenario: Timecop.freeze
|
7
|
+
Given I know the time the test started
|
8
|
+
When I GET "/time"
|
9
|
+
Then I should not receive the JSON:
|
10
|
+
"""
|
11
|
+
{
|
12
|
+
"time" : "{{time}}"
|
13
|
+
}
|
14
|
+
"""
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Given /^I know the time the test started$/ do
|
2
|
+
template_vars['time'] = Time.now.to_i
|
3
|
+
end
|
4
|
+
|
5
|
+
Then /^I should not receive the JSON:$/ do |json|
|
6
|
+
target = JSON.parse(render_string(json))
|
7
|
+
|
8
|
+
begin
|
9
|
+
received = JSON.parse(last_response.body)
|
10
|
+
rescue JSON::ParserError => e
|
11
|
+
raise "Unexpected response: #{last_response.body}\n#{e}"
|
12
|
+
end
|
13
|
+
|
14
|
+
expect(received).not_to eql(target)
|
15
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../../')
|
2
|
+
|
3
|
+
require 'lookout/rack/test/cucumber'
|
4
|
+
|
5
|
+
# Set up TestApp server
|
6
|
+
require 'examples/test_app'
|
7
|
+
$application_class = TestApp
|
8
|
+
require 'lookout/rack/test/cucumber/server'
|
9
|
+
|
10
|
+
require 'lookout/rack/test/cucumber/transforms'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
@timefreeze
|
2
|
+
Feature: Timefreeze and liquid templates
|
3
|
+
"""
|
4
|
+
This test happens in frozen time because it is tagged @timefreeze
|
5
|
+
"""
|
6
|
+
|
7
|
+
Scenario: Timecop.freeze
|
8
|
+
Given I know the time the test started
|
9
|
+
When I GET "/time"
|
10
|
+
Then I should receive the JSON:
|
11
|
+
"""
|
12
|
+
{
|
13
|
+
"time" : {{time}}
|
14
|
+
}
|
15
|
+
"""
|