hyperclient 0.9.3 → 2.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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.DS_Store +0 -0
  3. data/.github/dependabot.yml +18 -0
  4. data/.github/workflows/coverage.yml +24 -0
  5. data/.github/workflows/danger.yml +22 -0
  6. data/.github/workflows/lint.yml +16 -0
  7. data/.github/workflows/test.yml +23 -0
  8. data/.rubocop.yml +8 -3
  9. data/.rubocop_todo.yml +32 -41
  10. data/CHANGELOG.md +18 -0
  11. data/CONTRIBUTING.md +1 -1
  12. data/Gemfile +4 -4
  13. data/README.md +16 -9
  14. data/RELEASING.md +1 -1
  15. data/Rakefile +0 -8
  16. data/features/api_navigation.feature +5 -0
  17. data/features/steps/api_navigation.rb +19 -6
  18. data/features/steps/default_config.rb +2 -2
  19. data/features/support/api.rb +22 -5
  20. data/features/support/env.rb +14 -1
  21. data/features/support/fixtures.rb +96 -2
  22. data/hyperclient.gemspec +4 -6
  23. data/lib/hyperclient/entry_point.rb +4 -5
  24. data/lib/hyperclient/link.rb +21 -0
  25. data/lib/hyperclient/resource.rb +1 -3
  26. data/lib/hyperclient/resource_collection.rb +1 -3
  27. data/lib/hyperclient/version.rb +1 -1
  28. data/test/hyperclient/attributes_test.rb +9 -9
  29. data/test/hyperclient/collection_test.rb +15 -15
  30. data/test/hyperclient/curie_test.rb +4 -4
  31. data/test/hyperclient/entry_point_test.rb +46 -56
  32. data/test/hyperclient/link_collection_test.rb +14 -14
  33. data/test/hyperclient/link_test.rb +43 -43
  34. data/test/hyperclient/resource_collection_test.rb +6 -6
  35. data/test/hyperclient/resource_test.rb +28 -27
  36. data/test/hyperclient_test.rb +10 -11
  37. data/test/test_helper.rb +26 -3
  38. metadata +21 -66
  39. data/.travis.yml +0 -25
  40. data/lib/faraday/connection.rb +0 -17
  41. data/test/faraday/connection_test.rb +0 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30a6a424eb3f9cd9a70b19d49f3f9d3f3b952921fb6a2b034116296c7eb1e31f
4
- data.tar.gz: b35c0cd0abaa39753b53f59c0f718152acf3a8915b498d0acef4e7b8f2f0d82c
3
+ metadata.gz: '02694a72cb9a16a0faac55b463c859a470bce22f7976b0b77c19da138cceded8'
4
+ data.tar.gz: d96697a7e493f29b2a3207850b961664cfa18e0195b526abb16c9c108b2e2bc3
5
5
  SHA512:
6
- metadata.gz: 93c51dca3fa731081e1e82540d0c0f2d22f17e65ae336021b4b7199eac4ff1eecd3bd37e840cc02831e2d62b98d20a4a1e696dd5fba8bdd5ff51516f6bc763b6
7
- data.tar.gz: 9a2ad7090c37531384d42105754bc4d492ba711048d758b042863e43a43612317007d8446c02ad0efc88e09f95f6f5cdbb48239319724e1c2f35862f2ad92dcc
6
+ metadata.gz: 45bb98cc9a22fd721c71f32a4e7b2634610279fe66a8466d6f2339efb994853896ed33867baa3e460cd805055b2b2611108d703f7c7788b952ef3693393140fd
7
+ data.tar.gz: c3c47fee4c97362f31c40a8923eec8c7573be28e215a43bdaac89c44e573cd93cec57291932718dd1bd136689c9f46f1ceff2ace244d613d76871cf9e7529df6
data/.DS_Store ADDED
Binary file
@@ -0,0 +1,18 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ time: "04:00"
8
+ timezone: Europe/Madrid
9
+ open-pull-requests-limit: 10
10
+ ignore:
11
+ - dependency-name: rubocop
12
+ versions:
13
+ - 1.10.0
14
+ - 1.11.0
15
+ - 1.12.0
16
+ - 1.12.1
17
+ - 1.9.0
18
+ - 1.9.1
@@ -0,0 +1,24 @@
1
+ ---
2
+ name: coverage
3
+ on: [push, pull_request]
4
+
5
+ env:
6
+ COVERAGE: 1
7
+
8
+ jobs:
9
+ build:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v3
13
+ - name: Install Ruby (2.7)
14
+ uses: ruby/setup-ruby@v1
15
+ with:
16
+ ruby-version: 2.7
17
+ bundler-cache: true
18
+ - name: Build and test with RSpec
19
+ run: |
20
+ bundle exec rake test
21
+ - name: Coveralls
22
+ uses: coverallsapp/github-action@master
23
+ with:
24
+ github-token: ${{ secrets.GITHUB_TOKEN }}
@@ -0,0 +1,22 @@
1
+ ---
2
+ name: danger
3
+ on:
4
+ pull_request:
5
+ types: [opened, reopened, edited, synchronize]
6
+ jobs:
7
+ danger:
8
+ runs-on: ubuntu-20.04
9
+ steps:
10
+ - uses: actions/checkout@v3
11
+ with:
12
+ fetch-depth: 0
13
+ - name: Set up Ruby
14
+ uses: ruby/setup-ruby@v1
15
+ with:
16
+ ruby-version: 2.7
17
+ bundler-cache: true
18
+ - name: Run Danger
19
+ run: |
20
+ # the personal token is public, this is ok, base64 encode to avoid tripping Github
21
+ TOKEN=$(echo -n Z2hwX0xNQ3VmanBFeTBvYkZVTWh6NVNqVFFBOEUxU25abzBqRUVuaAo= | base64 --decode)
22
+ DANGER_GITHUB_API_TOKEN=$TOKEN bundle exec danger --verbose
@@ -0,0 +1,16 @@
1
+ name: lint
2
+ on: [push, pull_request]
3
+ jobs:
4
+ rubocop:
5
+ name: RuboCop
6
+ runs-on: ubuntu-latest
7
+ steps:
8
+ - name: Checkout
9
+ uses: actions/checkout@v3
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: '2.7'
14
+ bundler-cache: true
15
+ - run: bundle exec rubocop
16
+
@@ -0,0 +1,23 @@
1
+ ---
2
+ name: test
3
+ on: [push, pull_request]
4
+ jobs:
5
+ test:
6
+ runs-on: ubuntu-latest
7
+ strategy:
8
+ fail-fast: false
9
+ matrix:
10
+ entry:
11
+ - { ruby: '3.2' }
12
+ - { ruby: '2.7' }
13
+ - { ruby: 'ruby-head', allowed-failure: true }
14
+ - { ruby: 'jruby-head', allowed-failure: true }
15
+ name: test (${{ matrix.entry.ruby }})
16
+ steps:
17
+ - uses: actions/checkout@v3
18
+ - uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: ${{ matrix.entry.ruby }}
21
+ bundler-cache: true
22
+ - run: bundle exec rake test spinach
23
+ continue-on-error: ${{ matrix.entry.allowed-failure || false }}
data/.rubocop.yml CHANGED
@@ -1,10 +1,15 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
 
3
+ require:
4
+ - rubocop-rake
5
+ - rubocop-minitest
6
+
3
7
  AllCops:
8
+ NewCops: enable
4
9
  TargetRubyVersion: 2.3
5
10
 
6
- Metrics/BlockLength:
7
- ExcludedMethods: [it, describe]
11
+ Metrics:
12
+ Enabled: false
8
13
 
9
14
  Style/FrozenStringLiteralComment:
10
- Enabled: false
15
+ Enabled: false
data/.rubocop_todo.yml CHANGED
@@ -1,36 +1,52 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2020-05-10 19:37:12 -0400 using RuboCop version 0.81.0.
3
+ # on 2024-02-01 15:28:54 UTC using RuboCop version 1.48.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
9
  # Offense count: 1
10
- # Configuration parameters: CountComments.
11
- Metrics/ClassLength:
12
- Max: 103
10
+ # Configuration parameters: Severity, Include.
11
+ # Include: **/*.gemspec
12
+ Gemspec/RequiredRubyVersion:
13
+ Exclude:
14
+ - 'hyperclient.gemspec'
15
+
16
+ # Offense count: 1
17
+ # Configuration parameters: AllowComments, AllowEmptyLambdas.
18
+ Lint/EmptyBlock:
19
+ Exclude:
20
+ - 'test/hyperclient/entry_point_test.rb'
13
21
 
14
22
  # Offense count: 4
15
- # Configuration parameters: CountComments, ExcludedMethods.
16
- Metrics/MethodLength:
17
- Max: 25
23
+ Lint/MissingSuper:
24
+ Exclude:
25
+ - 'lib/hyperclient/attributes.rb'
26
+ - 'lib/hyperclient/entry_point.rb'
27
+ - 'lib/hyperclient/link_collection.rb'
28
+ - 'lib/hyperclient/resource_collection.rb'
18
29
 
19
- # Offense count: 3
20
- # Configuration parameters: CountComments.
21
- Metrics/ModuleLength:
22
- Max: 265
30
+ # Offense count: 1
31
+ # This cop supports unsafe autocorrection (--autocorrect-all).
32
+ # Configuration parameters: AllowedMethods.
33
+ # AllowedMethods: instance_of?, kind_of?, is_a?, eql?, respond_to?, equal?
34
+ Lint/RedundantSafeNavigation:
35
+ Exclude:
36
+ - 'lib/hyperclient/link.rb'
23
37
 
24
- # Offense count: 2
25
- # Cop supports --auto-correct.
26
- # Configuration parameters: AutoCorrect, EnforcedStyle.
38
+ # Offense count: 3
39
+ # This cop supports unsafe autocorrection (--autocorrect-all).
40
+ # Configuration parameters: EnforcedStyle.
27
41
  # SupportedStyles: nested, compact
28
42
  Style/ClassAndModuleChildren:
29
43
  Exclude:
30
44
  - 'features/steps/api_navigation.rb'
31
45
  - 'features/steps/default_config.rb'
46
+ - 'features/support/env.rb'
32
47
 
33
- # Offense count: 4
48
+ # Offense count: 5
49
+ # Configuration parameters: AllowedConstants.
34
50
  Style/Documentation:
35
51
  Exclude:
36
52
  - 'spec/**/*'
@@ -38,30 +54,5 @@ Style/Documentation:
38
54
  - 'features/steps/api_navigation.rb'
39
55
  - 'features/steps/default_config.rb'
40
56
  - 'features/support/api.rb'
57
+ - 'features/support/env.rb'
41
58
  - 'features/support/fixtures.rb'
42
-
43
- # Offense count: 2
44
- Style/DoubleNegation:
45
- Exclude:
46
- - 'lib/hyperclient/curie.rb'
47
- - 'lib/hyperclient/link.rb'
48
-
49
- # Offense count: 3
50
- # Cop supports --auto-correct.
51
- Style/IfUnlessModifier:
52
- Exclude:
53
- - 'lib/hyperclient/link_collection.rb'
54
- - 'lib/hyperclient/resource.rb'
55
- - 'lib/hyperclient/resource_collection.rb'
56
-
57
- # Offense count: 1
58
- Style/MethodMissingSuper:
59
- Exclude:
60
- - 'lib/hyperclient/collection.rb'
61
-
62
- # Offense count: 91
63
- # Cop supports --auto-correct.
64
- # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
65
- # URISchemes: http, https
66
- Layout/LineLength:
67
- Max: 142
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  ## Changelog
2
2
 
3
+ ### 2.0.0 (2024/02/01)
4
+
5
+ * [#268](https://github.com/codegram/hyperclient/pull/268): Replace Travis-CI with GHA - [@dblock](https://github.com/dblock).
6
+ * [#269](https://github.com/codegram/hyperclient/pull/269): Re-add code coverage - [@dblock](https://github.com/dblock).
7
+ * [#270](https://github.com/codegram/hyperclient/pull/270): Upgrade Rubocop to 1.45 - [@dblock](https://github.com/dblock).
8
+ * [#271](https://github.com/codegram/hyperclient/pull/271): Test against Ruby 3.2 - [@dblock](https://github.com/dblock).
9
+ * [#285](https://github.com/codegram/hyperclient/pull/285): Support Faraday 2.x - [@dblock](https://github.com/dblock).
10
+
11
+ ### 1.0.1 (2021/01/02)
12
+
13
+ * [#193](https://github.com/codegram/hyperclient/pull/193): Auto-paginate collections - [@dblock](https://github.com/dblock).
14
+ * [#163](https://github.com/codegram/hyperclient/pull/163): Test against Faraday 0.9, 0.17 and 1.0+ - [@dblock](https://github.com/dblock).
15
+ * [#199](https://github.com/codegram/hyperclient/pull/199): Use digest_auth from faraday-digestauth - [@dblock](https://github.com/dblock).
16
+
17
+ ### 1.0.0 (2021/01/02)
18
+
19
+ * NOTE: **⚠ This version has been yanked ⚠** - [@dblock](https://github.com/dblock).
20
+
3
21
  ### 0.9.3 (2020/05/14)
4
22
 
5
23
  * [#149](https://github.com/codegram/hyperclient/pull/149): Address Faraday warnings - [@yuki24](https://github.com/yuki24).
data/CONTRIBUTING.md CHANGED
@@ -106,7 +106,7 @@ git push origin my-feature-branch -f
106
106
 
107
107
  #### Check on Your Pull Request
108
108
 
109
- Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above.
109
+ Go back to your pull request after a few minutes and see whether it passed muster with CI. Everything should look green, otherwise fix issues and amend your commit as described above.
110
110
 
111
111
  #### Be Patient
112
112
 
data/Gemfile CHANGED
@@ -1,6 +1,3 @@
1
- # NOTE: this is temporary until Bundler 2.0 changes how github: references work.
2
- git_source(:github) { |repo| "https://github.com/#{repo['/'] ? repo : "#{repo}/#{repo}"}.git" }
3
-
4
1
  source 'https://rubygems.org'
5
2
 
6
3
  gemspec
@@ -16,8 +13,11 @@ end
16
13
 
17
14
  group :development, :test do
18
15
  gem 'rake'
19
- gem 'rubocop', '0.81.0', require: false
16
+ gem 'rubocop', '~> 1.48.0', require: false
17
+ gem 'rubocop-minitest', require: false
18
+ gem 'rubocop-rake', require: false
20
19
  gem 'simplecov', require: false
20
+ gem 'simplecov-lcov', require: false
21
21
  end
22
22
 
23
23
  group :test do
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Hyperclient
2
2
 
3
3
  [![Gem Version](http://img.shields.io/gem/v/hyperclient.svg)](http://badge.fury.io/rb/hyperclient)
4
- [![Build Status](http://img.shields.io/travis/codegram/hyperclient.svg)](https://travis-ci.org/codegram/hyperclient)
4
+ [![Build Status](https://github.com/codegram/hyperclient/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/codegram/hyperclient/actions/workflows/test.yml)
5
5
  [![Code Climate](https://codeclimate.com/github/codegram/hyperclient.svg)](https://codeclimate.com/github/codegram/hyperclient)
6
6
  [![Coverage Status](https://img.shields.io/coveralls/codegram/hyperclient.svg)](https://coveralls.io/r/codegram/hyperclient?branch=master)
7
7
 
@@ -25,7 +25,7 @@ Hyperclient is a Hypermedia API client written in Ruby. It fully supports [JSON
25
25
 
26
26
  # Usage
27
27
 
28
- The examples in this README use the [Splines Demo API](https://github.com/ruby-grape/grape-with-roar) running [here](https://grape-with-roar.herokuapp.com/api). If you're upgrading from a previous version, please make sure to read [UPGRADING](UPGRADING.md).
28
+ The examples in this README use the [Splines Demo API](https://github.com/ruby-grape/grape-with-roar) running [here](https://grape-with-roar.herokuapp.com/api). Use version 1.x with Faraday 1.x, and version 2.x with Faraday 2.x. If you're upgrading from a previous version, please make sure to read [UPGRADING](UPGRADING.md).
29
29
 
30
30
  ## API Client
31
31
 
@@ -50,7 +50,7 @@ Hyperclient constructs a connection using typical [Faraday](http://github.com/lo
50
50
  ```ruby
51
51
  api = Hyperclient.new('https://grape-with-roar.herokuapp.com/api') do |client|
52
52
  client.connection do |conn|
53
- conn.use Faraday::Request::OAuth
53
+ conn.use Faraday::Request::Instrumentation
54
54
  end
55
55
  end
56
56
  ```
@@ -60,7 +60,7 @@ You can pass options to the Faraday connection block in the `connection` block:
60
60
  ```ruby
61
61
  api = Hyperclient.new('https://grape-with-roar.herokuapp.com/api') do |client|
62
62
  client.connection(ssl: { verify: false }) do |conn|
63
- conn.use Faraday::Request::OAuth
63
+ conn.use Faraday::Request::Instrumentation
64
64
  end
65
65
  end
66
66
  ```
@@ -85,12 +85,19 @@ api = Hyperclient.new('https://grape-with-roar.herokuapp.com/api') do |client|
85
85
  end
86
86
  ```
87
87
 
88
- You can modify headers or specify authentication after a connection has been created. Hyperclient supports Basic, Token or Digest auth as well as many other Faraday extensions.
88
+ You can modify headers or specify authentication after a connection has been created. Hyperclient supports Basic, Token or [Digest auth](https://github.com/bhaberer/faraday-digestauth) as well as many other Faraday extensions.
89
89
 
90
90
  ```ruby
91
- api = Hyperclient.new('https://grape-with-roar.herokuapp.com/api')
92
- api.digest_auth('username', 'password')
93
- api.headers.update('Accept-Encoding' => 'deflate, gzip')
91
+ require 'faraday/digestauth'
92
+
93
+ api = Hyperclient.new('https://grape-with-roar.herokuapp.com/api') do |client|
94
+ client.connection(default: false) do |conn|
95
+ conn.request :digest, 'username', 'password'
96
+ conn.request :json
97
+ conn.response :json, content_type: /\bjson$/
98
+ conn.adapter :net_http
99
+ end
100
+ end
94
101
  ```
95
102
 
96
103
  You can access the Faraday connection directly after it has been created and add middleware to it. As an example, you could use the [faraday-http-cache-middleware](https://github.com/plataformatec/faraday-http-cache).
@@ -102,7 +109,7 @@ api.connection.use :http_cache
102
109
 
103
110
  ## Resources and Attributes
104
111
 
105
- Hyperclient will fetch and discover the resources from your API.
112
+ Hyperclient will fetch and discover the resources from your API and automatically paginate when possible.
106
113
 
107
114
  ```ruby
108
115
  api.splines.each do |spline|
data/RELEASING.md CHANGED
@@ -12,7 +12,7 @@ bundle install
12
12
  rake
13
13
  ```
14
14
 
15
- Check that the last build succeeded in [Travis CI](https://travis-ci.org/codegram/hyperclient) for all supported platforms.
15
+ Check that the last build succeeded in CI for all supported platforms.
16
16
 
17
17
  Increment the version, modify [lib/hyperclient/version.rb](lib/hyperclient/version.rb).
18
18
 
data/Rakefile CHANGED
@@ -6,14 +6,6 @@ Bundler.setup :default, :test, :development
6
6
 
7
7
  Bundler::GemHelper.install_tasks
8
8
 
9
- if ENV['COVERAGE']
10
- require 'simplecov'
11
- SimpleCov.start do
12
- add_filter '/test/'
13
- add_filter '/features/'
14
- end
15
- end
16
-
17
9
  require 'rake/testtask'
18
10
 
19
11
  Rake::TestTask.new(:test) do |t|
@@ -7,6 +7,11 @@ Feature: API navigation
7
7
  When I connect to the API
8
8
  Then I should be able to navigate to posts and authors
9
9
 
10
+ Scenario: Links
11
+ When I connect to the API
12
+ Then I should be able to paginate posts
13
+ Then I should be able to paginate authors
14
+
10
15
  Scenario: Templated links
11
16
  Given I connect to the API
12
17
  When I search for a post with a templated link
@@ -9,6 +9,19 @@ class Spinach::Features::ApiNavigation < Spinach::FeatureSteps
9
9
  assert_requested :get, 'http://api.example.org/authors'
10
10
  end
11
11
 
12
+ step 'I should be able to paginate posts' do
13
+ assert_kind_of Enumerator, api.posts.each
14
+ assert_equal 4, api.posts.to_a.count
15
+ assert_requested :get, 'http://api.example.org/posts'
16
+ assert_requested :get, 'http://api.example.org/posts?page=2'
17
+ assert_requested :get, 'http://api.example.org/posts?page=3'
18
+ end
19
+
20
+ step 'I should be able to paginate authors' do
21
+ assert_equal 1, api._links['api:authors'].to_a.count
22
+ assert_requested :get, 'http://api.example.org/authors'
23
+ end
24
+
12
25
  step 'I search for a post with a templated link' do
13
26
  api._links.search._expand(q: 'something')._resource
14
27
  end
@@ -30,13 +43,13 @@ class Spinach::Features::ApiNavigation < Spinach::FeatureSteps
30
43
  end
31
44
 
32
45
  step 'I should be able to access it\'s title and body' do
33
- @post._attributes.title.wont_equal nil
34
- @post._attributes.body.wont_equal nil
46
+ assert_kind_of String, @post._attributes.title
47
+ assert_kind_of String, @post._attributes.body
35
48
  end
36
49
 
37
50
  step 'I should also be able to access it\'s embedded comments' do
38
51
  comment = @post._embedded.comments.first
39
- comment._attributes.title.wont_equal nil
52
+ assert_kind_of String, comment._attributes.title
40
53
  end
41
54
 
42
55
  step 'I should be able to navigate to next page' do
@@ -50,8 +63,8 @@ class Spinach::Features::ApiNavigation < Spinach::FeatureSteps
50
63
  step 'I should be able to count embedded items' do
51
64
  assert_equal 2, api._links.posts._resource._embedded.posts.count
52
65
  assert_equal 2, api.posts._embedded.posts.count
53
- assert_equal 2, api.posts.count
54
- assert_equal 2, api.posts.map.count
66
+ assert_equal 4, api.posts.count
67
+ assert_equal 4, api.posts.map.count
55
68
  end
56
69
 
57
70
  step 'I should be able to iterate over embedded items' do
@@ -59,6 +72,6 @@ class Spinach::Features::ApiNavigation < Spinach::FeatureSteps
59
72
  api.posts.each do |_post|
60
73
  count += 1
61
74
  end
62
- assert_equal 2, count
75
+ assert_equal 4, count
63
76
  end
64
77
  end
@@ -25,7 +25,7 @@ class Spinach::Features::DefaultConfig < Spinach::FeatureSteps
25
25
  end
26
26
 
27
27
  step 'it should have been parsed as JSON' do
28
- @posts._attributes.total_posts.to_i.must_equal 2
29
- @posts._attributes['total_posts'].to_i.must_equal 2
28
+ assert_equal 4, @posts._attributes.total_posts.to_i
29
+ assert_equal 4, @posts._attributes['total_posts'].to_i
30
30
  end
31
31
  end
@@ -7,11 +7,28 @@ module API
7
7
  before do
8
8
  WebMock::Config.instance.query_values_notation = :flat_array
9
9
 
10
- stub_request(:any, /api.example.org*/).to_return(body: root_response, headers: { 'Content-Type' => 'application/hal+json' })
11
- stub_request(:get, 'api.example.org/posts').to_return(body: posts_response, headers: { 'Content-Type' => 'application/hal+json' })
12
- stub_request(:get, 'api.example.org/posts/1').to_return(body: post_response, headers: { 'Content-Type' => 'application/hal+json' })
13
- stub_request(:get, 'api.example.org/page2').to_return(body: page2_response, headers: { 'Content-Type' => 'application/hal+json' })
14
- stub_request(:get, 'api.example.org/page3').to_return(body: page3_response, headers: { 'Content-Type' => 'application/hal+json' })
10
+ stub_request(:any, /api.example.org*/).to_return(body: root_response,
11
+ headers: { 'Content-Type' => 'application/hal+json' })
12
+ stub_request(:get, 'api.example.org').to_return(body: root_response,
13
+ headers: { 'Content-Type' => 'application/hal+json' })
14
+ stub_request(:get, 'api.example.org/authors').to_return(body: authors_response,
15
+ headers: { 'Content-Type' => 'application/hal+json' })
16
+ stub_request(:get, 'api.example.org/posts').to_return(body: posts_response,
17
+ headers: { 'Content-Type' => 'application/hal+json' })
18
+ stub_request(:get, 'api.example.org/posts?page=2').to_return(body: posts_page2_response,
19
+ headers: { 'Content-Type' => 'application/hal+json' })
20
+ stub_request(:get, 'api.example.org/posts?page=3').to_return(body: posts_page3_response,
21
+ headers: { 'Content-Type' => 'application/hal+json' })
22
+ stub_request(:get, 'api.example.org/posts/1').to_return(body: post1_response,
23
+ headers: { 'Content-Type' => 'application/hal+json' })
24
+ stub_request(:get, 'api.example.org/posts/2').to_return(body: post2_response,
25
+ headers: { 'Content-Type' => 'application/hal+json' })
26
+ stub_request(:get, 'api.example.org/posts/3').to_return(body: post3_response,
27
+ headers: { 'Content-Type' => 'application/hal+json' })
28
+ stub_request(:get, 'api.example.org/page2').to_return(body: page2_response,
29
+ headers: { 'Content-Type' => 'application/hal+json' })
30
+ stub_request(:get, 'api.example.org/page3').to_return(body: page3_response,
31
+ headers: { 'Content-Type' => 'application/hal+json' })
15
32
  end
16
33
 
17
34
  def api
@@ -1,4 +1,17 @@
1
- require 'minitest/spec'
1
+ require 'minitest'
2
2
  require 'webmock'
3
3
  WebMock.enable!
4
4
  require 'hyperclient'
5
+
6
+ Minitest::Spec.new nil if defined?(Minitest::Spec)
7
+ Spinach.config[:failure_exceptions] << Minitest::Assertion
8
+
9
+ class Spinach::FeatureSteps
10
+ include Minitest::Assertions
11
+ attr_accessor :assertions
12
+
13
+ def initialize(*args)
14
+ super(*args)
15
+ self.assertions = 0
16
+ end
17
+ end
@@ -15,13 +15,32 @@ module Spinach
15
15
  }'
16
16
  end
17
17
 
18
+ def authors_response
19
+ '{
20
+ "_links": {
21
+ "self": { "href": "/authors" }
22
+ },
23
+ "_embedded": {
24
+ "api:authors": [
25
+ {
26
+ "name": "Lorem Ipsum",
27
+ "_links": {
28
+ "self": { "href": "/authors/1" }
29
+ }
30
+ }
31
+ ]
32
+ }
33
+ }'
34
+ end
35
+
18
36
  def posts_response
19
37
  '{
20
38
  "_links": {
21
39
  "self": { "href": "/posts" },
40
+ "next": {"href": "/posts?page=2"},
22
41
  "last_post": {"href": "/posts/1"}
23
42
  },
24
- "total_posts": "2",
43
+ "total_posts": "4",
25
44
  "_embedded": {
26
45
  "posts": [
27
46
  {
@@ -43,7 +62,48 @@ module Spinach
43
62
  }'
44
63
  end
45
64
 
46
- def post_response
65
+ def posts_page2_response
66
+ '{
67
+ "_links": {
68
+ "self": { "href": "/posts?page=2" },
69
+ "next": { "href": "/posts?page=3" }
70
+ },
71
+ "total_posts": "4",
72
+ "_embedded": {
73
+ "posts": [
74
+ {
75
+ "title": "My third blog post",
76
+ "body": "Lorem ipsum dolor sit amet",
77
+ "_links": {
78
+ "self": { "href": "/posts/3" }
79
+ }
80
+ }
81
+ ]
82
+ }
83
+ }'
84
+ end
85
+
86
+ def posts_page3_response
87
+ '{
88
+ "_links": {
89
+ "self": { "href": "/posts?page=3" }
90
+ },
91
+ "total_posts": "4",
92
+ "_embedded": {
93
+ "posts": [
94
+ {
95
+ "title": "My third blog post",
96
+ "body": "Lorem ipsum dolor sit amet",
97
+ "_links": {
98
+ "self": { "href": "/posts/4" }
99
+ }
100
+ }
101
+ ]
102
+ }
103
+ }'
104
+ end
105
+
106
+ def post1_response
47
107
  '{
48
108
  "_links": {
49
109
  "self": { "href": "/posts/1" }
@@ -60,6 +120,40 @@ module Spinach
60
120
  }'
61
121
  end
62
122
 
123
+ def post2_response
124
+ '{
125
+ "_links": {
126
+ "self": { "href": "/posts/2" }
127
+ },
128
+ "title": "My first blog post",
129
+ "body": "Lorem ipsum dolor sit amet",
130
+ "_embedded": {
131
+ "comments": [
132
+ {
133
+ "title": "Some comment"
134
+ }
135
+ ]
136
+ }
137
+ }'
138
+ end
139
+
140
+ def post3_response
141
+ '{
142
+ "_links": {
143
+ "self": { "href": "/posts/3" }
144
+ },
145
+ "title": "My first blog post",
146
+ "body": "Lorem ipsum dolor sit amet",
147
+ "_embedded": {
148
+ "comments": [
149
+ {
150
+ "title": "Some comment"
151
+ }
152
+ ]
153
+ }
154
+ }'
155
+ end
156
+
63
157
  def page2_response
64
158
  '{
65
159
  "_links": {