rspec-resources 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dfb441b28de8568ca1eb074a1e62b67aec0e3f1f
4
+ data.tar.gz: 78e04e0fe569a3a90be7fa90dc3eb4df37c12693
5
+ SHA512:
6
+ metadata.gz: 549c60cbf01019fe906f1f571e2a8edb0d57674ff5485bcfe7ff4d727c12b357ba8dd3417bbbd0f522006a6241dd474658561fee2fcfa7e040c5c244657b103e
7
+ data.tar.gz: ffcc0265869be1451e0bef0fda95d3870dc6ca82da8fa62a2f976a129ee63d22a8fca2fce841fec72dafa35e0f3dfc4838bc8250c10a92b5c31fecdd47dd17d5
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ /.vscode
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,27 @@
1
+ require: rubocop-rspec
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.4
5
+ Exclude:
6
+ - 'bin/*'
7
+
8
+ Style/Documentation:
9
+ Enabled: false
10
+
11
+ Metrics/LineLength:
12
+ Max: 120
13
+
14
+ Metrics/MethodLength:
15
+ Max: 20
16
+
17
+ Style/TrailingCommaInArrayLiteral:
18
+ Enabled: false
19
+
20
+ Style/TrailingCommaInHashLiteral:
21
+ Enabled: false
22
+
23
+ Style/TrailingCommaInArguments:
24
+ Enabled: false
25
+
26
+ Metrics/AbcSize:
27
+ Max: 25
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.3
5
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at davidpoetzsch@web.de. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in rspec-resources.gemspec
8
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,67 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rspec-resources (0.1.0)
5
+ activesupport (>= 3.0.0)
6
+ rspec (~> 3.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (5.1.6)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ ast (2.4.0)
17
+ concurrent-ruby (1.0.5)
18
+ diff-lcs (1.3)
19
+ i18n (1.0.0)
20
+ concurrent-ruby (~> 1.0)
21
+ minitest (5.11.3)
22
+ parallel (1.12.1)
23
+ parser (2.5.0.5)
24
+ ast (~> 2.4.0)
25
+ powerpack (0.1.1)
26
+ rainbow (3.0.0)
27
+ rake (10.5.0)
28
+ rspec (3.7.0)
29
+ rspec-core (~> 3.7.0)
30
+ rspec-expectations (~> 3.7.0)
31
+ rspec-mocks (~> 3.7.0)
32
+ rspec-core (3.7.1)
33
+ rspec-support (~> 3.7.0)
34
+ rspec-expectations (3.7.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.7.0)
37
+ rspec-mocks (3.7.0)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.7.0)
40
+ rspec-support (3.7.1)
41
+ rubocop (0.54.0)
42
+ parallel (~> 1.10)
43
+ parser (>= 2.5)
44
+ powerpack (~> 0.1)
45
+ rainbow (>= 2.2.2, < 4.0)
46
+ ruby-progressbar (~> 1.7)
47
+ unicode-display_width (~> 1.0, >= 1.0.1)
48
+ rubocop-rspec (1.24.0)
49
+ rubocop (>= 0.53.0)
50
+ ruby-progressbar (1.9.0)
51
+ thread_safe (0.3.6)
52
+ tzinfo (1.2.5)
53
+ thread_safe (~> 0.1)
54
+ unicode-display_width (1.3.0)
55
+
56
+ PLATFORMS
57
+ ruby
58
+
59
+ DEPENDENCIES
60
+ bundler (~> 1.16)
61
+ rake (~> 10.0)
62
+ rspec-resources!
63
+ rubocop
64
+ rubocop-rspec
65
+
66
+ BUNDLED WITH
67
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 David Poetzsch-Heffter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # rspec-resources
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rspec/resources`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rspec-resources'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rspec-resources
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rspec-resources. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the rspec-resources project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rspec-resources/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rspec/resources"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec
4
+ module Resources
5
+ module DSL
6
+ module Actions
7
+ class IncludeIfNeeded
8
+ def initialize(context, action)
9
+ @ctx = context
10
+ @action = action
11
+ end
12
+
13
+ attr_reader :action
14
+
15
+ def auth_examples
16
+ with_meta_for :it_needs_authentication do |incl_meta|
17
+ context 'when authentication is missing' do
18
+ let(incl_meta[:headers]) { {} }
19
+
20
+ it "denies access with status code #{incl_meta[:error_status]}" do
21
+ expect(response).to have_http_status(incl_meta[:error_status])
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ def restricted_examples
28
+ with_meta_for :it_has_restricted_access do |incl_meta|
29
+ case action
30
+ when :index then restricted_index_examples incl_meta
31
+ when :create then restricted_create_examples incl_meta
32
+ else
33
+ context 'when trying to access a restricted resource' do
34
+ subject { send incl_meta[:for_resource] }
35
+
36
+ it "denies access with status code #{incl_meta[:error_status]}" do
37
+ expect(response).to have_http_status(incl_meta[:error_status])
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def restricted_index_examples(incl_meta)
47
+ context 'when only restricted resources are in database' do
48
+ subject { [send(incl_meta[:for_resource])] }
49
+
50
+ if Util.nested_resource? metadata
51
+ # we can not access the parent resource
52
+ # thus we get a not found error
53
+ it { returns_status_code 404 }
54
+ else
55
+ it 'returns no records' do
56
+ expect(json_data).to be_empty
57
+ end
58
+
59
+ it { returns_status_code 200 }
60
+ end
61
+ end
62
+ end
63
+
64
+ def restricted_create_examples(incl_meta)
65
+ return unless Util.nested_resource? metadata
66
+
67
+ context 'when using a restricted parent resource' do
68
+ let(:instantiation_resource) { send incl_meta[:for_resource] }
69
+
70
+ it { returns_status_code 404 }
71
+ end
72
+ end
73
+
74
+ def context(*args, &block)
75
+ @ctx.context(*args, &block)
76
+ end
77
+
78
+ def metadata
79
+ @ctx.metadata
80
+ end
81
+
82
+ def with_meta_for(key)
83
+ incl_meta = metadata[key]
84
+ return if incl_meta.nil? || !incl_meta[:only].include?(action)
85
+
86
+ yield incl_meta
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,121 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec/resources/dsl/actions/include_if_needed'
4
+
5
+ module RSpec
6
+ module Resources
7
+ module DSL
8
+ module Actions
9
+ extend ActiveSupport::Concern
10
+
11
+ module ClassMethods
12
+ def describe_index(&block)
13
+ path = metadata[:base_path]
14
+
15
+ describe "GET #{path}" do
16
+ subject { [accessible_resource] }
17
+
18
+ before do
19
+ subject # force subject creation
20
+ get instantiate_path(path, subject.first), headers: request_headers
21
+ end
22
+
23
+ instance_eval(&block)
24
+
25
+ include_if_needed(:index).auth_examples
26
+ include_if_needed(:index).restricted_examples
27
+ end
28
+ end
29
+
30
+ def describe_show(&block)
31
+ path = id_path_template
32
+
33
+ describe "GET #{path}" do
34
+ subject { accessible_resource }
35
+
36
+ before { get instantiate_path(path, subject), headers: request_headers }
37
+
38
+ instance_eval(&block)
39
+
40
+ include_if_needed(:show).auth_examples
41
+ include_if_needed(:show).restricted_examples
42
+ end
43
+ end
44
+
45
+ def describe_create(&block)
46
+ path = metadata[:base_path]
47
+
48
+ describe "POST #{path}" do
49
+ let(:params) { |ce| attributes_for(ce.metadata[:resource_name]) }
50
+ let(:instantiation_resource) { accessible_resource }
51
+
52
+ before do |current_example|
53
+ if Util.nested_resource? current_example.metadata
54
+ # we need to fill in the other ids with valid stuff
55
+ instpath = instantiate_path(path, instantiation_resource)
56
+ instantiation_resource.destroy!
57
+ else
58
+ instpath = path
59
+ end
60
+
61
+ post instpath, params: params.to_json, headers: request_headers
62
+ end
63
+
64
+ instance_eval(&block)
65
+
66
+ include_if_needed(:create).auth_examples
67
+ include_if_needed(:create).restricted_examples
68
+ end
69
+ end
70
+
71
+ def describe_update(&block)
72
+ path = id_path_template
73
+
74
+ describe "PATCH/PUT #{path}" do
75
+ subject { accessible_resource }
76
+
77
+ let(:params) { |ce| attributes_for(ce.metadata[:resource_name]) }
78
+
79
+ before { patch instantiate_path(path, subject), params: params.to_json, headers: request_headers }
80
+
81
+ instance_eval(&block)
82
+
83
+ include_if_needed(:update).auth_examples
84
+ include_if_needed(:update).restricted_examples
85
+ end
86
+ end
87
+
88
+ def describe_destroy(&block)
89
+ path = id_path_template
90
+
91
+ describe "DELETE #{path}" do
92
+ subject { accessible_resource }
93
+
94
+ before { delete instantiate_path(path, subject), headers: request_headers }
95
+
96
+ instance_eval(&block)
97
+
98
+ include_if_needed(:destroy).auth_examples
99
+ include_if_needed(:destroy).restricted_examples
100
+ end
101
+ end
102
+
103
+ private
104
+
105
+ def include_if_needed(action)
106
+ IncludeIfNeeded.new(self, action)
107
+ end
108
+
109
+ def id_path_template
110
+ path = metadata[:base_path]
111
+ metadata[:single_resource] ? path : (path + '/:id')
112
+ end
113
+ end
114
+
115
+ def instantiate_path(path, obj)
116
+ path.gsub(/:\w+/) { |s| obj[s[1..-1]] }
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec
4
+ module Resources
5
+ module DSL
6
+ module Characteristics
7
+ extend ActiveSupport::Concern
8
+
9
+ module ClassMethods
10
+ def visible_attributes(*params)
11
+ params = params.first if params.length == 1 && params.first.is_a?(Array)
12
+ let(:visible_attributes) { params }
13
+ end
14
+
15
+ def it_needs_authentication(with_headers: :auth_headers, only: %i[index show create update destroy])
16
+ metadata[:it_needs_authentication] = {
17
+ headers: with_headers,
18
+ error_status: 401,
19
+ only: only,
20
+ }
21
+
22
+ metadata[:request_headers] ||= []
23
+ metadata[:request_headers].push with_headers
24
+ end
25
+
26
+ def it_has_restricted_access(for_resource: :restricted_resource, only: %i[index show create update destroy])
27
+ metadata[:it_has_restricted_access] = {
28
+ for_resource: for_resource,
29
+ error_status: 404,
30
+ only: only,
31
+ }
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec
4
+ module Resources
5
+ module DSL
6
+ module Matchers
7
+ extend ActiveSupport::Concern
8
+
9
+ def returns_the_records(*records)
10
+ try_set_description 'returns the requested records'
11
+
12
+ expect(json).to have_key('data')
13
+ expect(json_data.length).to eq(records.length)
14
+
15
+ json_data.each_with_index do |jd, i|
16
+ expect(jd['attributes']).to equal_record(records[i], on: visible_attributes)
17
+ end
18
+ end
19
+
20
+ def returns_the_subject
21
+ if subject.is_a? Array
22
+ returns_the_records(*subject)
23
+ else
24
+ try_set_description 'returns the requested record'
25
+ expect(json).to have_key('data')
26
+ expect(json_data['attributes']).to equal_record(subject, on: visible_attributes)
27
+ end
28
+ end
29
+
30
+ def creates_a_new_record
31
+ try_set_description 'creates a new record with the given attributes'
32
+
33
+ record = accessible_resource.class.find_by_id(json_data['id'])
34
+ expect(record).to be_present
35
+ expect(record).to match_params
36
+ end
37
+
38
+ def updates_the_subject
39
+ try_set_description 'updates the record with the given attributes'
40
+
41
+ expect(subject.reload).to match_params
42
+ end
43
+
44
+ def destroys_the_subject
45
+ try_set_description 'deletes the record'
46
+
47
+ expect(subject.class.find_by_id(subject.id)).to be_nil
48
+ end
49
+
50
+ private
51
+
52
+ def try_set_description(desc)
53
+ return if RSpec.current_example.metadata[:description].present?
54
+ RSpec.current_example.metadata[:description] = desc
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec/resources/dsl/actions'
4
+ require 'rspec/resources/dsl/characteristics'
5
+ require 'rspec/resources/dsl/matchers'
6
+
7
+ module RSpec
8
+ module Resources
9
+ module DSL
10
+ # Custom describe block that sets metadata to enable easy resource testing.
11
+ # This directly correlates with the `resources` directive of the rails routes file.
12
+ #
13
+ # describe_resources '/v1/articles', meta: :data do
14
+ # # ...
15
+ # end
16
+ #
17
+ # Params:
18
+ # +base_path+:: The resources base path, typically the one of the index action
19
+ # +options+:: RSpec's `describe` metadata arguments
20
+ # +block+:: Block to pass into describe
21
+ #
22
+ def describe_resources(base_path, options = {}, &block)
23
+ abstract_describe(base_path, { single_resource: false }.merge(options), &block)
24
+ end
25
+
26
+ # Custom describe block that sets metadata to enable easy resource testing.
27
+ # In contrast to `#describe_resources` this method is meant for resources where only one instance exists.
28
+ # This directly correlates with the `resource` directive of the rails routes file.
29
+ #
30
+ # describe_resources '/v1/profile', meta: :data do
31
+ # # ...
32
+ # end
33
+ #
34
+ # Params:
35
+ # +base_path+:: The resource base path, typically the one of the get action
36
+ # +options+:: RSpec's `describe` metadata arguments
37
+ # +block+:: Block to pass into describe
38
+ #
39
+ def describe_resource(base_path, options = {}, &block)
40
+ abstract_describe(base_path, { single_resource: true }.merge(options), &block)
41
+ end
42
+
43
+ private
44
+
45
+ def abstract_describe(base_path, options = {}, &block)
46
+ name = base_path.split('/').last
47
+
48
+ dopts = {
49
+ type: :request,
50
+ base_path: base_path,
51
+ resource_name: name.singularize,
52
+ rspec_resources_dsl: :resource,
53
+ }.merge(options)
54
+
55
+ RSpec.describe(name.capitalize, dopts) do
56
+ let(:request_headers) do |current_example|
57
+ (current_example.metadata[:request_headers] || []).map { |s| send s }.inject { |x, y| x.merge y }
58
+ end
59
+
60
+ instance_eval(&block)
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ RSpec::Core::ExampleGroup.extend(RSpec::Resources::DSL)
68
+ RSpec::Core::DSL.expose_example_group_alias(:describe_resources)
69
+ RSpec::Core::DSL.expose_example_group_alias(:describe_resource)
70
+
71
+ RSpec.configuration.include RSpec::Resources::DSL::Actions, rspec_resources_dsl: :resource
72
+ RSpec.configuration.include RSpec::Resources::DSL::Characteristics, rspec_resources_dsl: :resource
73
+ RSpec.configuration.include RSpec::Resources::DSL::Matchers, rspec_resources_dsl: :resource
74
+ # RSpec.configuration.backtrace_exclusion_patterns << %r{lib/rspec/resources/dsl/}
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec
4
+ module Resources
5
+ module Util
6
+ def self.nested_resource?(metadata)
7
+ metadata[:base_path] =~ /:\w+/
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec
4
+ module Resources
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support'
4
+
5
+ require 'rspec/resources/util'
6
+ require 'rspec/resources/dsl'
7
+ require 'rspec/resources/version'
8
+
9
+ module RSpec
10
+ module Resources
11
+ end
12
+ end
@@ -0,0 +1,33 @@
1
+
2
+ # frozen_string_literal: true
3
+
4
+ lib = File.expand_path('lib', __dir__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require 'rspec/resources/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'rspec-resources'
10
+ spec.version = RSpec::Resources::VERSION
11
+ spec.authors = ['David Poetzsch-Heffter']
12
+ spec.email = ['davidpoetzsch@web.de']
13
+
14
+ spec.summary = 'A concise DSL for testing rails resources with rspec'
15
+ # spec.description = 'TODO: Write a longer description or delete this line.'
16
+ spec.homepage = 'https://github.com/dpoetzsch/rspec-resources'
17
+ spec.license = 'MIT'
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
+ f.match(%r{^(test|spec|features)/})
21
+ end
22
+ spec.bindir = 'exe'
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_runtime_dependency 'rspec', '~> 3.0'
27
+ spec.add_runtime_dependency 'activesupport', '>= 3.0.0'
28
+
29
+ spec.add_development_dependency 'bundler', '~> 1.16'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'rubocop'
32
+ spec.add_development_dependency 'rubocop-rspec'
33
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-resources
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Poetzsch-Heffter
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-04-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 3.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - davidpoetzsch@web.de
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".rubocop.yml"
107
+ - ".travis.yml"
108
+ - CODE_OF_CONDUCT.md
109
+ - Gemfile
110
+ - Gemfile.lock
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - bin/console
115
+ - bin/setup
116
+ - lib/rspec/resources.rb
117
+ - lib/rspec/resources/dsl.rb
118
+ - lib/rspec/resources/dsl/actions.rb
119
+ - lib/rspec/resources/dsl/actions/include_if_needed.rb
120
+ - lib/rspec/resources/dsl/characteristics.rb
121
+ - lib/rspec/resources/dsl/matchers.rb
122
+ - lib/rspec/resources/util.rb
123
+ - lib/rspec/resources/version.rb
124
+ - rspec-resources.gemspec
125
+ homepage: https://github.com/dpoetzsch/rspec-resources
126
+ licenses:
127
+ - MIT
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.6.14.1
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: A concise DSL for testing rails resources with rspec
149
+ test_files: []