capybara_api_helpers 0.0.2

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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OWYzNDJjZGFlMzcwNDZlNGMyMWY4NjIzZDZlOTJiMGU1ZDJjYTBlMA==
5
+ data.tar.gz: !binary |-
6
+ OGY3YmY0M2NiYTQxNjE0ZDUxOTkxNDNiYTQwZjRhNTlkZDVjYTZjYQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NWY3MmY0MTZkMjNhZGMwYjBlNDZiZTFmZDIxMTllNTE3YTA4NmI3MTg5MGVk
10
+ MWIxNmNiNTUwYTFhZTI3YmY3MDBkYTkyZjk4NDY1NzhkYmM2NmQ1NmE5OGI3
11
+ ZTVhYzI1MjE1YjkyZTYzMTg1NTc4MzZkOGNkZTRiNTc1N2ZlMjM=
12
+ data.tar.gz: !binary |-
13
+ YTMxYTdjOGQ2MWQ5M2Y5ZjRhZmMwYWIwZWFjYjlkNzljNDUwM2UwZTcwN2Qw
14
+ OWYwZWI0Yzg1ODY5MjY2YmQ1MDZiMTRhODQzZTA2Y2U1ODRiOWJkY2U4Zjdl
15
+ NmJmZjJhM2QxNzI0OGUzNDliZTBmNGFlYjg1MTQ5ZGZjNzAzOWU=
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capybara_api_helpers.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Jon Evans
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,59 @@
1
+ # CapybaraApiHelpers
2
+
3
+ Simple helpers for testing an API with Capybara and rspec.
4
+
5
+ [You're not supposed to test APIs with Capybara](http://www.elabs.se/blog/34-capybara-and-testing-apis),
6
+ but sometimes it's convenient.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'capybara_api_helpers'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install capybara_api_helpers
23
+
24
+ In your `spec_helper.rb`, add this line:
25
+
26
+ `config.include CapybaraApiHelpers, type: :feature`
27
+
28
+ ## Usage
29
+
30
+ In your specs, you can now test your api with the methods `hit_api` (which defaults to GET),
31
+ `put_api`, and `post_api`. They will do what (I hope) is expected, and will use the JSON format.
32
+
33
+ Here's an example:
34
+
35
+ ```ruby
36
+ response = hit_api 'v2/things'
37
+
38
+ expect(response.size).to eq 5
39
+
40
+ first_thing = things.first
41
+
42
+ expect(first_thing['name']).to eq 'Chapstick'
43
+ ```
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it ( https://github.com/[my-github-username]/capybara_api_helpers/fork )
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create a new Pull Request
52
+
53
+ ## About Foraker Labs
54
+
55
+ <img src="http://assets.foraker.com/foraker_logo.png" width="400" height="62">
56
+
57
+ This project is maintained by Foraker Labs. The names and logos of Foraker Labs are fully owned and copyright Foraker Design, LLC.
58
+
59
+ Foraker Labs is a Boulder-based Ruby on Rails and iOS development shop. Please reach out if we can [help build your product](http://www.foraker.com).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capybara_api_helpers/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "capybara_api_helpers"
8
+ spec.version = CapybaraApiHelpers::VERSION
9
+ spec.authors = ["Jon Evans"]
10
+ spec.email = ["jle@foraker.com"]
11
+ spec.summary = %q{Ease testing of JSON APIs with Capybara and rspec.}
12
+ spec.description = %q{Testing APIs with Capybara isn't a great idea, but this makes it easier if you want to anyway.}
13
+ spec.homepage = "https://github.com/foraker/capybara_api_helpers"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,23 @@
1
+ require "capybara_api_helpers/version"
2
+
3
+ module CapybaraApiHelpers
4
+ def hit_api(path, parameters = {}, method = :get)
5
+ path = ["/", path, ".json"].join
6
+
7
+ if method == :get
8
+ visit([path, parameters.to_query].compact.join('?'))
9
+ else
10
+ page.driver.submit(method, path, parameters)
11
+ end
12
+
13
+ JSON.parse(page.body) rescue page.body
14
+ end
15
+
16
+ def post_api(path, parameters = {})
17
+ hit_api(path, parameters, :post)
18
+ end
19
+
20
+ def put_api(path, parameters = {})
21
+ hit_api(path, parameters, :put)
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module CapybaraApiHelpers
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capybara_api_helpers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Jon Evans
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Testing APIs with Capybara isn't a great idea, but this makes it easier
42
+ if you want to anyway.
43
+ email:
44
+ - jle@foraker.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - capybara_api_helpers.gemspec
55
+ - lib/capybara_api_helpers.rb
56
+ - lib/capybara_api_helpers/version.rb
57
+ homepage: https://github.com/foraker/capybara_api_helpers
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.2.2
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Ease testing of JSON APIs with Capybara and rspec.
81
+ test_files: []