prolog_minitest_matchers 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fab4720efbabb4f86251454fb1107c3b12b133e2
4
- data.tar.gz: 10d7bb2ce0ce02a2308193a66d1853b89ba45d57
3
+ metadata.gz: 3432250c36aada7c4efaf78622e1c6f538ce804d
4
+ data.tar.gz: d312f4b46721223e8796c7b8a08b714335719fd3
5
5
  SHA512:
6
- metadata.gz: e44d46dde47f14931e9056e898e6b10a9361d48f314b3ad1b810dbe8681e4d246689a6b30a9a722307601c72d8d09bee0d34a1db7d7fa9deadd67f6c9f3e9853
7
- data.tar.gz: 488130da26e438b86938551ced8286f7fbb2252e28923fe0e27d9f03961d40e062d3a78b5371e1ff0e6024db7ffc7861448d5a0aa1e769466defb39d7bcedf91
6
+ metadata.gz: 9c5dcf648b266d338d43023504adcf61004828cca72b101deef1a373570cf010f7ebcf8a640c59fa7e3068713a06f5cdc9f86329648a23950df792bc7ff0e2b6
7
+ data.tar.gz: 09a985e617ed970d21f272838491612672ab8f6c59e7b2f700d8f4866ddd1ddb48b02deb54e5ce0bcce34522084ca4981b91d68d9f9e24cb98edb058fd3118e3
data/.rubocop.yml ADDED
@@ -0,0 +1,4 @@
1
+
2
+ AllCops:
3
+ TargetRubyVersion: 2.3
4
+
data/Rakefile CHANGED
@@ -1,10 +1,47 @@
1
+
1
2
  require "bundler/gem_tasks"
2
3
  require "rake/testtask"
3
4
 
5
+ require 'rake/tasklib'
6
+ require 'flay'
7
+ require 'flay_task'
8
+ require 'tasks/prolog_flog_task'
9
+ require 'reek/rake/task'
10
+ require 'rubocop/rake_task'
11
+
4
12
  Rake::TestTask.new(:test) do |t|
5
13
  t.libs << "test"
6
14
  t.libs << "lib"
7
15
  t.test_files = FileList['test/**/*_test.rb']
8
16
  end
9
17
 
10
- task :default => :test
18
+ RuboCop::RakeTask.new(:rubocop) do |task|
19
+ task.patterns = [
20
+ 'lib/**/*.rb',
21
+ 'test/**/*.rb'
22
+ ]
23
+ task.formatters = ['simple', 'd']
24
+ task.fail_on_error = true
25
+ task.options << '--display-cop-names'
26
+ end
27
+
28
+ Reek::Rake::Task.new do |t|
29
+ t.config_file = 'config.reek'
30
+ t.source_files = 'lib/**/*.rb'
31
+ t.reek_opts = '--sort-by smelliness -s'
32
+ end
33
+
34
+ FlayTask.new do |t|
35
+ t.verbose = true
36
+ t.dirs = %w(lib)
37
+ end
38
+
39
+ FlogTask.new do |t|
40
+ t.verbose = true
41
+ t.threshold = 200 # default is 200
42
+ t.methods_only = true
43
+ t.dirs = %w(lib)
44
+ end
45
+
46
+ task(:default).clear
47
+ task default: [:test, :rubocop, :flay, :flog, :reek]
data/config.reek ADDED
@@ -0,0 +1,8 @@
1
+
2
+ LongParameterList:
3
+ max_params: 4 # If it's good enough for Sandi, it's good enough for us.
4
+
5
+ # NestedIterators:
6
+ # max_allowed_nesting: 2
7
+ # ignore_iterators:
8
+ # - lambda
@@ -25,34 +25,44 @@ module MiniTest
25
25
  errors[:expected]&.message == message
26
26
  end
27
27
 
28
+ def filtered_params
29
+ full_params.dup.reject { |source_key, _| source_key == param_key }
30
+ end
31
+
32
+ # Running Reek will complain about a :reek:ControlParameter. Protocol is.
28
33
  def initial_message_from(message, param_key)
29
34
  message || "missing keyword: #{param_key}"
30
35
  end
31
36
 
32
37
  def save_and_try_to_init
33
38
  verify_param_in_list
34
- saved_item = full_params[param_key]
35
- full_params.delete param_key
36
- errors = try_to_init
37
- full_params[param_key] = saved_item
38
- errors
39
+ save_and_delete_param_before { |params| try_to_init params }
40
+ end
41
+
42
+ def save_and_delete_param_before
43
+ yield filtered_params
39
44
  end
40
45
 
41
- def try_to_init
46
+ def try_to_init(params)
42
47
  expected_error = nil
43
48
  begin
44
- _ = klass.new full_params
49
+ klass.new params
45
50
  rescue ArgumentError => error
46
51
  expected_error = error
47
- rescue StandardError => error
48
- ap [:matcher_48, 'Unexpected error', error]
49
52
  end
50
53
  { expected: expected_error }
51
54
  end
52
55
 
53
56
  def verify_param_in_list
54
- no_param_message = "No key :#{param_key} in #{full_params}!"
55
- fail KeyError, no_param_message unless full_params.key?(param_key)
57
+ raise KeyError, no_param_message unless param_in_full_list?
58
+ end
59
+
60
+ def no_param_message
61
+ "No key :#{param_key} in #{full_params}!"
62
+ end
63
+
64
+ def param_in_full_list?
65
+ full_params.key? param_key
56
66
  end
57
67
  end # class MiniTest::Assertions::AssertRequiresInitializeParameter
58
68
  end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MiniTest
4
+ # Adding custom assertions to make specs easier to read
5
+ module Assertions
6
+ # Actual test logic for `#assert_requires_static_call_paramr`.
7
+ class AssertRequiresStaticCallParam
8
+ def initialize(klass, full_params, param_key, message)
9
+ @klass = klass
10
+ @full_params = full_params
11
+ @param_key = param_key
12
+ @message = initial_message_from(message, param_key)
13
+ self
14
+ end
15
+
16
+ def call(assert)
17
+ verify_param_in_list(assert)
18
+ assert.call(errors_as_expected(save_and_try_to_call), message)
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :full_params, :klass, :message, :param_key
24
+
25
+ def errors_as_expected(errors)
26
+ errors[:expected]&.message == message
27
+ end
28
+
29
+ def filtered_params
30
+ full_params.dup.reject { |source_key, _| source_key == param_key }
31
+ end
32
+
33
+ # Running Reek will complain about a :reek:ControlParameter. Protocol is.
34
+ def initial_message_from(message, param_key)
35
+ message || "missing keyword: #{param_key}"
36
+ end
37
+
38
+ def key_not_found_message
39
+ "Key :#{param_key} not found in #{full_params}!"
40
+ end
41
+
42
+ def save_and_try_to_call
43
+ save_and_delete_param_before { |params| try_to_call params }
44
+ # saved_item = full_params[param_key]
45
+ # full_params.delete param_key
46
+ # errors = try_to_call
47
+ # full_params[param_key] = saved_item
48
+ # errors
49
+ end
50
+
51
+ def try_to_call(params)
52
+ expected_error = nil
53
+ begin
54
+ klass.call params
55
+ rescue ArgumentError => error
56
+ expected_error = error
57
+ end
58
+ { expected: expected_error }
59
+ end
60
+
61
+ def save_and_delete_param_before
62
+ yield filtered_params
63
+ end
64
+
65
+ def verify_param_in_list(assert)
66
+ assert.call(param_in_list?, key_not_found_message)
67
+ end
68
+
69
+ def param_in_list?
70
+ full_params.key?(param_key)
71
+ end
72
+ end # class MiniTest::Assertions::AssertRequiresStaticCallParam
73
+ end
74
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'minitest/spec'
4
+
5
+ require_relative './asserters/assert_requires_static_call_param.rb'
6
+
7
+ module MiniTest
8
+ # Adding custom assertions to make specs easier to read
9
+ module Assertions
10
+ def assert_requires_static_call_param(klass, full_params, param_key,
11
+ message = nil)
12
+ AssertRequiresStaticCallParam.new(klass, full_params, param_key, message)
13
+ .call(method(:assert))
14
+ end
15
+ end
16
+
17
+ # Make it available to MiniTest::Spec
18
+ module Expectations
19
+ infect_an_assertion :assert_requires_static_call_param,
20
+ :must_require_static_call_param, :reverse
21
+ end
22
+ end # module MiniTest
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Module to satisfy Gem requirements; nothing inside but version-spec constant.
3
4
  module PrologMinitestMatchers
4
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
5
6
  end
@@ -3,6 +3,7 @@
3
3
  require 'prolog_minitest_matchers/version'
4
4
  require 'prolog_minitest_matchers/matchers/requires_initialize_parameter'
5
5
 
6
+ # Module to satisfy Gem requirements; nothing inside but version-spec constant.
6
7
  module PrologMinitestMatchers
7
- # Your code goes here...
8
+ # Your code would go here if it wasn't required to go elsewhere...
8
9
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rake/tasklib'
4
+ require 'flog'
5
+ require 'flog_task'
6
+
7
+ # Redefinition of standard task's Rake invocation. Because we don't like
8
+ # inconsistency in option settings.
9
+ class FlogTask < Rake::TaskLib
10
+ # Reek bitches that this is a :reek:Attribute (writable). That's the *point*.
11
+ attr_accessor :methods_only
12
+ end
@@ -30,4 +30,10 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "bundler", "~> 1.12", ">= 1.12.5"
31
31
  spec.add_development_dependency "rake", "~> 11.2", ">= 11.2.2"
32
32
  spec.add_development_dependency "minitest", "~> 5.9", ">= 5.9.0"
33
+
34
+ spec.add_development_dependency "flay", "~> 2.8", ">= 2.8.0"
35
+ spec.add_development_dependency "flog", "~> 4.4", ">= 4.4.0"
36
+ spec.add_development_dependency "reek", "~> 4.2", ">= 4.2.1"
37
+ spec.add_development_dependency "rubocop", "~> 0.42", ">= 0.42.0"
38
+ spec.add_development_dependency "pry-byebug", "~> 3.4", ">= 3.4.0"
33
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prolog_minitest_matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Dickey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-20 00:00:00.000000000 Z
11
+ date: 2016-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,6 +70,106 @@ dependencies:
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
72
  version: 5.9.0
73
+ - !ruby/object:Gem::Dependency
74
+ name: flay
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '2.8'
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 2.8.0
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.8'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 2.8.0
93
+ - !ruby/object:Gem::Dependency
94
+ name: flog
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '4.4'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 4.4.0
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '4.4'
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 4.4.0
113
+ - !ruby/object:Gem::Dependency
114
+ name: reek
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '4.2'
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: 4.2.1
123
+ type: :development
124
+ prerelease: false
125
+ version_requirements: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '4.2'
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 4.2.1
133
+ - !ruby/object:Gem::Dependency
134
+ name: rubocop
135
+ requirement: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '0.42'
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: 0.42.0
143
+ type: :development
144
+ prerelease: false
145
+ version_requirements: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: '0.42'
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: 0.42.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: pry-byebug
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '3.4'
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: 3.4.0
163
+ type: :development
164
+ prerelease: false
165
+ version_requirements: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - "~>"
168
+ - !ruby/object:Gem::Version
169
+ version: '3.4'
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: 3.4.0
73
173
  description:
74
174
  email:
75
175
  - jdickey@seven-sigma.com
@@ -78,16 +178,21 @@ extensions: []
78
178
  extra_rdoc_files: []
79
179
  files:
80
180
  - ".gitignore"
181
+ - ".rubocop.yml"
81
182
  - ".travis.yml"
82
183
  - CODE_OF_CONDUCT.md
83
184
  - Gemfile
84
185
  - LICENSE.txt
85
186
  - README.md
86
187
  - Rakefile
188
+ - config.reek
87
189
  - lib/prolog_minitest_matchers.rb
88
190
  - lib/prolog_minitest_matchers/matchers/asserters/assert_requires_initialize_parameter.rb
191
+ - lib/prolog_minitest_matchers/matchers/asserters/assert_requires_static_call_param.rb
89
192
  - lib/prolog_minitest_matchers/matchers/requires_initialize_parameter.rb
193
+ - lib/prolog_minitest_matchers/matchers/requires_static_call_param.rb
90
194
  - lib/prolog_minitest_matchers/version.rb
195
+ - lib/tasks/prolog_flog_task.rb
91
196
  - prolog_minitest_matchers.gemspec
92
197
  homepage: https://github.com/TheProlog/prolog_minitest_matchers
93
198
  licenses: