rspec-parameterized-core 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c8154f0d17983d93033899679942929337ebc2fbfffea858f1d6d9696dfb24fd
4
+ data.tar.gz: e4d2f7c5632141c43855df2a9010f44dd157adc963bf5def65ac98517447a81c
5
+ SHA512:
6
+ metadata.gz: ff1e240ac4458d5dfe73d7b3a2f6573a4a0f06aeedc6abab0f4c0389769b7b71a210e93a5fbb8d8bfbc2f6510dcd4cd740abfae03be983920f656aafcdb1741f
7
+ data.tar.gz: d02178da387a6471bd261770a3724e0158eeae210fff51b4b1fe44093d892e3700112d765a94711299974d9156fb5eb0e46aa5969f833030c831e96f75941c9c
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-12-31
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in rspec-parameterized-core.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 sue445
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,35 @@
1
+ # Rspec::Parameterized::Core
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ 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/parameterized/core`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ 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.
26
+
27
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rspec-parameterized-core.
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
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: %i[spec]
@@ -0,0 +1,9 @@
1
+ module RSpec
2
+ module Parameterized
3
+ module Core
4
+ class Arg
5
+ def apply(obj) ; end
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,21 @@
1
+ module RSpec
2
+ module Parameterized
3
+ module Core
4
+ module ExampleHelperMethods
5
+ def recursive_apply(val)
6
+ return val.apply(self) if HelperMethods.applicable?(val)
7
+
8
+ if val.is_a?(Array)
9
+ return val.map { |child_val| recursive_apply(child_val) }
10
+ end
11
+
12
+ if val.is_a?(Hash)
13
+ return val.map { |key, value| [recursive_apply(key), recursive_apply(value)] }.to_h
14
+ end
15
+
16
+ val
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'rspec/parameterized/core/ref_arg'
2
+ require 'rspec/parameterized/core/lazy_arg'
3
+ module RSpec
4
+ module Parameterized
5
+ module Core
6
+ module HelperMethods
7
+ def ref(symbol)
8
+ RefArg.new(symbol)
9
+ end
10
+
11
+ def lazy(&block)
12
+ LazyArg.new(&block)
13
+ end
14
+
15
+ def self.applicable?(arg)
16
+ arg.is_a? Arg
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module RSpec
2
+ module Parameterized
3
+ module Core
4
+ class LazyArg < Arg
5
+ def initialize(&block)
6
+ @block = block
7
+ end
8
+
9
+ def apply(obj)
10
+ obj.instance_eval(&@block)
11
+ end
12
+
13
+ def inspect
14
+ "#{@block.to_raw_source}"
15
+ rescue Parser::SyntaxError
16
+ super.inspect
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ require 'rspec/parameterized/core/arg'
2
+ module RSpec
3
+ module Parameterized
4
+ module Core
5
+ class RefArg < Arg
6
+ def initialize(symbol)
7
+ @symbol = symbol
8
+ end
9
+
10
+ def apply(obj)
11
+ obj.send(@symbol)
12
+ end
13
+
14
+ def inspect
15
+ "#{@symbol}"
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rspec
4
+ module Parameterized
5
+ module Core
6
+ VERSION = "1.0.0.beta1"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,178 @@
1
+ require "rspec/parameterized/core/version"
2
+ require 'parser'
3
+ require 'unparser'
4
+ require 'proc_to_ast'
5
+ require 'rspec/parameterized/core/helper_methods'
6
+ require 'rspec/parameterized/core/example_helper_methods'
7
+
8
+ module RSpec
9
+ module Parameterized
10
+ module Core
11
+ module ExampleGroupMethods
12
+ # capsulize parameter attributes
13
+ class Parameter
14
+ attr_reader :arg_names, :block
15
+
16
+ def initialize(arg_names, &block)
17
+ @arg_names, @block = arg_names, block
18
+ end
19
+ end
20
+
21
+ # Set parameters to be bound in specs under this example group.
22
+ #
23
+ # ## Example1
24
+ #
25
+ # where(:a, :b, :answer) do
26
+ # [
27
+ # [1 , 2 , 3],
28
+ # [5 , 8 , 13],
29
+ # [0 , 0 , 0]
30
+ # ]
31
+ # end
32
+ #
33
+ # ## Example2
34
+ # using RSpec::Parameterized::TableSyntax
35
+ # where(:a, :b, :answer) do
36
+ # 1 | 2 | 3 >
37
+ # 5 | 8 | 13 >
38
+ # 0 | 0 | 0
39
+ # end
40
+ #
41
+ def where(*args, &b)
42
+
43
+ if args.size == 1 && args[0].instance_of?(Hash)
44
+ naming_func = args.first.delete(:case_names)
45
+ params = args[0]
46
+ first, *rest = params.values
47
+ arg_names = params.keys
48
+ arg_values = first.product(*rest)
49
+
50
+ if naming_func && naming_func.respond_to?(:call)
51
+ arg_names << :case_name
52
+ arg_values.map! { |row| row << naming_func.call(*row) }
53
+ end
54
+
55
+ set_parameters(arg_names) {
56
+ arg_values
57
+ }
58
+ elsif args.size == 0
59
+ set_verbose_parameters(&b)
60
+ else
61
+ set_parameters(args, &b)
62
+ end
63
+ end
64
+
65
+ # Use parameters to execute the block.
66
+ # The given block is converted into +describe+s for each parameter set.
67
+ #
68
+ # ## Example
69
+ # with_them do
70
+ # it "should do additions" do
71
+ # (a + b).should == answer
72
+ # end
73
+ # end
74
+ #
75
+ def with_them(*args, &b)
76
+ opts = args.last.is_a?(Hash) ? args.pop : {}
77
+ opts[:caller] = caller unless opts[:caller]
78
+ args.push(opts)
79
+ @parameter ||= nil
80
+
81
+ if @parameter.nil?
82
+ @parameterized_pending_cases ||= []
83
+ @parameterized_pending_cases << [args, b]
84
+ else
85
+ define_cases(@parameter, *args, &b)
86
+ end
87
+ end
88
+
89
+ private
90
+ def set_parameters(arg_names, &b)
91
+ @parameter = Parameter.new(arg_names, &b)
92
+ @parameterized_pending_cases ||= []
93
+
94
+ @parameterized_pending_cases.each { |e|
95
+ define_cases(@parameter, *e[0], &e[1])
96
+ }
97
+ end
98
+
99
+ def define_cases(parameter, *args, &block)
100
+ instance = new # for evaluate let methods.
101
+ instance.extend HelperMethods
102
+ if defined?(self.superclass::LetDefinitions)
103
+ instance.extend self.superclass::LetDefinitions
104
+ end
105
+
106
+ extracted = instance.instance_eval(&parameter.block)
107
+ param_sets = extracted.is_a?(Array) ? extracted : extracted.to_params
108
+
109
+ # for only one parameters
110
+ param_sets = param_sets.map { |x| Array[x] } if !param_sets[0].is_a?(Array)
111
+
112
+ param_sets.each do |param_set|
113
+ pairs = [parameter.arg_names, param_set].transpose.to_h
114
+ pretty_params = pairs.has_key?(:case_name) ? pairs[:case_name] : pairs.map {|name, val| "#{name}: #{params_inspect(val)}"}.join(", ")
115
+ describe(pretty_params, *args) do
116
+ include ExampleHelperMethods
117
+
118
+ pairs.each do |name, val|
119
+ let(name) { recursive_apply(val) }
120
+ end
121
+
122
+ singleton_class.module_eval do
123
+ if respond_to?(:params)
124
+ warn "ExampleGroup.params method is overrided."
125
+ end
126
+
127
+ define_method(:params) do
128
+ pairs
129
+ end
130
+
131
+ if respond_to?(:all_params)
132
+ warn "ExampleGroup.all_params method is overrided."
133
+ end
134
+
135
+ define_method(:all_params) do
136
+ param_sets
137
+ end
138
+ end
139
+
140
+ module_eval(&block)
141
+ end
142
+ end
143
+ end
144
+
145
+ def params_inspect(obj)
146
+ begin
147
+ obj.is_a?(Proc) ? obj.to_raw_source : obj.inspect
148
+ rescue Parser::SyntaxError
149
+ return obj.inspect
150
+ end
151
+ end
152
+
153
+ def set_verbose_parameters(&block)
154
+ arguments_hash = yield
155
+ arg_names = arguments_hash.values.reduce(Set.new) { |memo, pairs| memo | pairs.keys }.to_a
156
+ arg_values = []
157
+ arguments_hash.each do |name, values_hash|
158
+ row = [name]
159
+ arg_names.each do |argument_name|
160
+ row << values_hash[argument_name]
161
+ end
162
+ arg_values << row
163
+ end
164
+ arg_names.unshift(:case_name)
165
+ set_parameters(arg_names) {
166
+ arg_values
167
+ }
168
+ end
169
+ end
170
+ end
171
+ end
172
+
173
+ module Core
174
+ class ExampleGroup
175
+ extend ::RSpec::Parameterized::Core::ExampleGroupMethods
176
+ end
177
+ end
178
+ end
@@ -0,0 +1 @@
1
+ require 'rspec/parameterized/core'
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/rspec/parameterized/core/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rspec-parameterized-core"
7
+ spec.version = Rspec::Parameterized::Core::VERSION
8
+ spec.authors = ["sue445", "tomykaira", "joker1007"]
9
+ spec.email = ["sue445@sue445.net", "tomykaira@gmail.com"]
10
+
11
+ spec.description = %q{RSpec::Parameterized supports simple parameterized test syntax in rspec.}
12
+ spec.summary = %q{RSpec::Parameterized supports simple parameterized test syntax in rspec.
13
+ I was inspired by [udzura's mock](https://gist.github.com/1881139).}
14
+
15
+ spec.homepage = "https://github.com/rspec-parameterized/rspec-parameterized-core"
16
+ spec.license = "MIT"
17
+ spec.required_ruby_version = ">= 2.6.0"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = spec.homepage
21
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
28
+ end
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ spec.add_dependency "parser"
35
+ spec.add_dependency "proc_to_ast"
36
+ spec.add_dependency "rspec", ">= 2.13", "< 4"
37
+ spec.add_dependency "unparser"
38
+
39
+ spec.add_development_dependency "rake", ">= 12.0.0"
40
+
41
+ # For more information and examples about making a new gem, check out our
42
+ # guide at: https://bundler.io/guides/creating_gem.html
43
+ end
@@ -0,0 +1,8 @@
1
+ module Rspec
2
+ module Parameterized
3
+ module Core
4
+ VERSION: String
5
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
6
+ end
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-parameterized-core
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.beta1
5
+ platform: ruby
6
+ authors:
7
+ - sue445
8
+ - tomykaira
9
+ - joker1007
10
+ autorequire:
11
+ bindir: exe
12
+ cert_chain: []
13
+ date: 2022-12-31 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: parser
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: proc_to_ast
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rspec
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '2.13'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '4'
53
+ type: :runtime
54
+ prerelease: false
55
+ version_requirements: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '2.13'
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: '4'
63
+ - !ruby/object:Gem::Dependency
64
+ name: unparser
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ - !ruby/object:Gem::Dependency
78
+ name: rake
79
+ requirement: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 12.0.0
84
+ type: :development
85
+ prerelease: false
86
+ version_requirements: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: 12.0.0
91
+ description: RSpec::Parameterized supports simple parameterized test syntax in rspec.
92
+ email:
93
+ - sue445@sue445.net
94
+ - tomykaira@gmail.com
95
+ executables: []
96
+ extensions: []
97
+ extra_rdoc_files: []
98
+ files:
99
+ - ".rspec"
100
+ - CHANGELOG.md
101
+ - Gemfile
102
+ - LICENSE.txt
103
+ - README.md
104
+ - Rakefile
105
+ - lib/rspec-parameterized-core.rb
106
+ - lib/rspec/parameterized/core.rb
107
+ - lib/rspec/parameterized/core/arg.rb
108
+ - lib/rspec/parameterized/core/example_helper_methods.rb
109
+ - lib/rspec/parameterized/core/helper_methods.rb
110
+ - lib/rspec/parameterized/core/lazy_arg.rb
111
+ - lib/rspec/parameterized/core/ref_arg.rb
112
+ - lib/rspec/parameterized/core/version.rb
113
+ - rspec-parameterized-core.gemspec
114
+ - sig/rspec/parameterized/core.rbs
115
+ homepage: https://github.com/rspec-parameterized/rspec-parameterized-core
116
+ licenses:
117
+ - MIT
118
+ metadata:
119
+ homepage_uri: https://github.com/rspec-parameterized/rspec-parameterized-core
120
+ source_code_uri: https://github.com/rspec-parameterized/rspec-parameterized-core
121
+ changelog_uri: https://github.com/rspec-parameterized/rspec-parameterized-core/blob/main/CHANGELOG.md
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: 2.6.0
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">"
134
+ - !ruby/object:Gem::Version
135
+ version: 1.3.1
136
+ requirements: []
137
+ rubygems_version: 3.2.22
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: RSpec::Parameterized supports simple parameterized test syntax in rspec.
141
+ I was inspired by [udzura's mock](https://gist.github.com/1881139).
142
+ test_files: []