rspec-compliance_table 0.1.6 → 0.1.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90750874c85953a18b4a5d3c5214100fce700c235afb6be8b79ba194f46caa08
4
- data.tar.gz: eddd6559b4d0abb2cdb8588f8059edf21f179580b45bad99bd82cd74d78087d8
3
+ metadata.gz: 3e928054175664fec26b4c1a13f879023e31b2fa3bac0d295b26b6ed5deb8f8c
4
+ data.tar.gz: 6e1518ec3f2a1d3693e2f287834d171341a5ee518db320b4c8735244295f8e91
5
5
  SHA512:
6
- metadata.gz: e13b3913f917d8b5a569b117b5919e729f880b6afd83d97b46bf6bd7f185a262cfe09628d0a1494efd07e4c1c287c81545c6f8a1a807a8e45cb0a7afca51714b
7
- data.tar.gz: b35cdfe77124c98c06253124c70793cfd1c6a6942a0ec91a0b6ec2929156d15a85e99dbc229a0c5115e24ca723facc6f897ecc2048b38c4ad853fa26b50dd8d1
6
+ metadata.gz: abe2016fd822e477f6fb8fb2813d23ca5a0a6f0c7af99be5a92c2c414ff90fa0ce992685c361c47283094b4b37fabda5afe0a962cc92cc65e6a73e44532ae3d9
7
+ data.tar.gz: 4b941940c3240a6d1e788c60db171520c088451d5bd3fb33d4d53c9a118285fc0ead6900b42248bbe03674e8196507d306af3801d16fad099e99de67333cbae8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-compliance_table (0.1.5)
4
+ rspec-compliance_table (0.1.6)
5
5
  activesupport (>= 4.0.0)
6
6
  pastel (~> 0.7)
7
7
  terminal-table (~> 1.8)
@@ -15,15 +15,20 @@ GEM
15
15
  minitest (~> 5.1)
16
16
  tzinfo (~> 1.1)
17
17
  zeitwerk (~> 2.2)
18
+ coderay (1.1.2)
18
19
  concurrent-ruby (1.1.5)
19
20
  diff-lcs (1.3)
20
21
  equatable (0.6.1)
21
22
  i18n (1.7.0)
22
23
  concurrent-ruby (~> 1.0)
24
+ method_source (1.0.0)
23
25
  minitest (5.13.0)
24
26
  pastel (0.7.3)
25
27
  equatable (~> 0.6)
26
28
  tty-color (~> 0.5)
29
+ pry (0.13.1)
30
+ coderay (~> 1.1)
31
+ method_source (~> 1.0)
27
32
  rake (10.5.0)
28
33
  rspec (3.9.0)
29
34
  rspec-core (~> 3.9.0)
@@ -52,6 +57,7 @@ PLATFORMS
52
57
 
53
58
  DEPENDENCIES
54
59
  bundler (~> 1.17)
60
+ pry
55
61
  rake (~> 10.0)
56
62
  rspec (~> 3.0)
57
63
  rspec-compliance_table!
@@ -6,20 +6,23 @@ require 'terminal-table'
6
6
  require 'rspec/core'
7
7
  require 'rspec/expectations'
8
8
  require 'rspec/compliance_table/version'
9
+ require 'rspec/compliance_table/configuration'
9
10
 
10
11
  require 'active_support/core_ext/object/blank'
11
12
  require 'active_support/core_ext/array/access'
12
13
 
13
14
  # rubocop:disable all
14
15
  module RSpec
15
- # Adds `compliance_for`
16
- # as a RSpec custom example
17
16
  module ComplianceTable
18
- COMPLIANCE_TOKEN = 'yay'
17
+ COMPLIANCE_TOKEN = 'y'
19
18
  SCENARIO_HEADER_TOKEN = 'scenario'
20
19
 
21
20
  class MissingAction < StandardError; end
22
21
 
22
+ def self.configure
23
+ yield(Configuration.instance)
24
+ end
25
+
23
26
  def compliance_for(record_name, table, options = {})
24
27
  table = prepare_table(table)
25
28
 
@@ -27,7 +30,7 @@ module RSpec
27
30
  scenarios = scenarios(table)
28
31
  compliance = compliance(table)
29
32
 
30
- raise_if_missing_permission(actions, options)
33
+ raise_if_missing_action(actions, options)
31
34
 
32
35
  expected_table = {}.tap do |parsed_table|
33
36
  actions.each_with_index do |act, act_index|
@@ -59,16 +62,13 @@ module RSpec
59
62
  table.split("\n").reject(&:blank?)
60
63
  end
61
64
 
62
- def raise_if_missing_permission(actions, options)
65
+ def raise_if_missing_action(actions, options)
63
66
  options[:ignore] ||= []
64
67
 
65
- existing_actions = described_class.instance_methods(false).map(&:to_s)
66
-
67
- if (actions.map(&:to_s) & existing_actions).length == (existing_actions - options[:ignore].map(&:to_s)).length
68
- return
69
- end
68
+ expected_actions = (Configuration.instance.actions_for(described_class).presence).map(&:to_s)
69
+ not_mapped_actions = (expected_actions - options[:ignore].map(&:to_s)) - (actions.map(&:to_s) & expected_actions)
70
70
 
71
- raise MissingAction, "The compliance table provided doesn't have every possible action for this permission"
71
+ raise MissingAction, "The compliance table doesn't have every possible action for the #{described_class} class. The missing actions were: #{not_mapped_actions.join(',')}" if not_mapped_actions.any?
72
72
  end
73
73
 
74
74
  def run_compliance_matchers(expected_table, actions, scenarios, _boolean_values, record_name)
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'singleton'
4
+
5
+ # rubocop:disable all
6
+ module RSpec
7
+ module ComplianceTable
8
+ class Configuration
9
+ include Singleton
10
+
11
+ def whitelist(options = {})
12
+ @whitelist ||= options
13
+ end
14
+
15
+ def actions_for(described_class)
16
+ return described_class.instance_methods(false) if @whitelist.nil?
17
+ return described_class.instance_methods(false) if @whitelist[:match_actions_from].nil?
18
+
19
+ described_class.const_get(@whitelist[:match_actions_from])
20
+ end
21
+ end
22
+ end
23
+ end
24
+ # rubocop:enable all
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Rspec
3
+ module RSpec
4
4
  module ComplianceTable
5
- VERSION = '0.1.6'
5
+ VERSION = '0.1.7'
6
6
  end
7
7
  end
@@ -6,7 +6,7 @@ require 'rspec/compliance_table/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = 'rspec-compliance_table'
9
- spec.version = Rspec::ComplianceTable::VERSION
9
+ spec.version = RSpec::ComplianceTable::VERSION
10
10
  spec.authors = ['Luis Vasconcellos']
11
11
  spec.email = ['luis@luisvasconcellos.com']
12
12
 
@@ -44,4 +44,5 @@ Gem::Specification.new do |spec|
44
44
  spec.add_development_dependency 'bundler', '~> 1.17'
45
45
  spec.add_development_dependency 'rake', '~> 10.0'
46
46
  spec.add_development_dependency 'rspec', '~> 3.0'
47
+ spec.add_development_dependency 'pry'
47
48
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-compliance_table
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luis Vasconcellos
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-21 00:00:00.000000000 Z
11
+ date: 2020-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: A rspec compliance table for permission testing
98
112
  email:
99
113
  - luis@luisvasconcellos.com
@@ -114,6 +128,7 @@ files:
114
128
  - bin/console
115
129
  - bin/setup
116
130
  - lib/rspec/compliance_table.rb
131
+ - lib/rspec/compliance_table/configuration.rb
117
132
  - lib/rspec/compliance_table/version.rb
118
133
  - rspec-compliance_table.gemspec
119
134
  homepage: http://luisvasconcellos.com