├── .github ├── dependabot.yml └── workflows │ └── rspec.yml ├── .gitignore ├── .rspec ├── CHANGELOG.md ├── Gemfile ├── LICENSE ├── README.md ├── Rakefile ├── UPGRADING.md ├── lib ├── rspec-parameterized.rb └── rspec │ ├── parameterized.rb │ └── parameterized │ └── version.rb ├── rspec-parameterized.gemspec └── spec ├── parametarized_spec.rb └── spec_helper.rb /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # c.f. https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file 2 | version: 2 3 | 4 | updates: 5 | - package-ecosystem: github-actions 6 | directory: / 7 | schedule: 8 | interval: monthly 9 | -------------------------------------------------------------------------------- /.github/workflows/rspec.yml: -------------------------------------------------------------------------------- 1 | name: RSpec 2 | 3 | on: 4 | push: 5 | branches: [ $default-branch ] 6 | pull_request: 7 | 8 | jobs: 9 | test: 10 | 11 | runs-on: ubuntu-latest 12 | strategy: 13 | matrix: 14 | ruby-version: 15 | - '2.7' 16 | - '3.0' 17 | - '3.1' 18 | - '3.2' 19 | - '3.3' 20 | - '3.4' 21 | 22 | steps: 23 | - uses: actions/checkout@v4 24 | - name: Set up Ruby 25 | # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, 26 | # change this to (see https://github.com/ruby/setup-ruby#versioning): 27 | uses: ruby/setup-ruby@v1 28 | with: 29 | ruby-version: ${{ matrix.ruby-version }} 30 | bundler-cache: true # runs 'bundle install' and caches installed gems automatically 31 | - name: Run tests 32 | run: bundle exec rake 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | .bundle 4 | .config 5 | .yardoc 6 | Gemfile.lock 7 | InstalledFiles 8 | _yardoc 9 | coverage 10 | doc/ 11 | lib/bundler/man 12 | pkg 13 | rdoc 14 | spec/reports 15 | test/tmp 16 | test/version_tmp 17 | tmp 18 | 19 | gemfiles/*.lock 20 | gemfiles/.bundle 21 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | --format progress 3 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | ## Unreleased 3 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v2.0.0...master) 4 | 5 | ## [v2.0.0](https://github.com/tomykaira/rspec-parameterized/releases/tag/v2.0.0) (2025-05-02) 6 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v1.0.2...v2.0.0) 7 | 8 | - Requires rspec-parameterized-core v2 and rspec-parameterized-table_syntax v2 9 | - https://github.com/tomykaira/rspec-parameterized/pull/90 10 | 11 | see also 12 | 13 | - rspec-parameterized-core 14 | - https://github.com/rspec-parameterized/rspec-parameterized-core/blob/main/CHANGELOG.md#200---2025-05-02 15 | - https://github.com/rspec-parameterized/rspec-parameterized-core/releases/tag/v2.0.0 16 | - rspec-parameterized-table_syntax 17 | - https://github.com/rspec-parameterized/rspec-parameterized-table_syntax/blob/main/CHANGELOG.md#200---2025-05-02 18 | - https://github.com/rspec-parameterized/rspec-parameterized-table_syntax/releases/tag/v2.0.0 19 | 20 | ## [v1.0.2](https://github.com/tomykaira/rspec-parameterized/tree/v1.0.1) (2024-04-28) 21 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v1.0.1...v1.0.2) 22 | 23 | - Hard-code the license name 24 | - https://github.com/tomykaira/rspec-parameterized/pull/88 25 | 26 | ## [v1.0.1](https://github.com/tomykaira/rspec-parameterized/tree/v1.0.1) (2024-04-28) 27 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v1.0.0...v1.0.1) 28 | 29 | - Reference LICENSE file in .gemspec 30 | - https://github.com/tomykaira/rspec-parameterized/pull/87 31 | 32 | ## [v1.0.0](https://github.com/tomykaira/rspec-parameterized/tree/v1.0.0) (2022-12-31) 33 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.5.3...v1.0.0) 34 | 35 | - Split gems 36 | - https://github.com/tomykaira/rspec-parameterized/issues/82 37 | - https://github.com/tomykaira/rspec-parameterized/pull/83 38 | 39 | See also 40 | 41 | - [Upgrading Guide](UPGRADING.md#v10) 42 | - https://github.com/rspec-parameterized/rspec-parameterized-table_syntax/blob/main/CHANGELOG.md#100---2022-12-31 43 | - https://github.com/rspec-parameterized/rspec-parameterized-core/blob/main/CHANGELOG.md#100---2022-12-31 44 | 45 | ## [v0.5.3](https://github.com/tomykaira/rspec-parameterized/tree/v0.5.3) (2022-12-29) 46 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.5.2...v0.5.3) 47 | 48 | - Fix uninitialized instance variable warning 49 | - https://github.com/tomykaira/rspec-parameterized/pull/78 50 | - Support Ruby 3.2 51 | - https://github.com/tomykaira/rspec-parameterized/pull/81 52 | - https://github.com/tomykaira/rspec-parameterized/issues/80 53 | 54 | ## [v0.5.2](https://github.com/tomykaira/rspec-parameterized/tree/v0.5.2) (2022-06-24) 55 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.5.1...v0.5.2) 56 | 57 | - Made MFA mandatory for gem releases 58 | - https://github.com/tomykaira/rspec-parameterized/pull/79 59 | 60 | ## [v0.5.1](https://github.com/tomykaira/rspec-parameterized/tree/v0.5.1) (2022-01-04) 61 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.5.0...v0.5.1) 62 | 63 | - Changes to apply method calls recursively when parameter is Array or Hash. 64 | - https://github.com/tomykaira/rspec-parameterized/pull/75 65 | 66 | ## [v0.5.0](https://github.com/tomykaira/rspec-parameterized/tree/v0.5.0) (2021-06-29) 67 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.4.2...v0.5.0) 68 | 69 | - Support new parameter type: ref and lazy 70 | - https://github.com/tomykaira/rspec-parameterized/pull/62 71 | - https://github.com/tomykaira/rspec-parameterized/pull/65 72 | 73 | ## [v0.4.2](https://github.com/tomykaira/rspec-parameterized/tree/v0.4.2) (2019-04-26) 74 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.4.1...v0.4.2) 75 | 76 | - Support jruby 77 | - https://github.com/tomykaira/rspec-parameterized/pull/54 78 | - https://github.com/tomykaira/rspec-parameterized/issues/49 79 | 80 | ## [v0.4.1](https://github.com/tomykaira/rspec-parameterized/tree/v0.4.1) (2018-12-06) 81 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.4.0...v0.4.1) 82 | 83 | - Replace binding_of_caller with binding_ninja 84 | - https://github.com/tomykaira/rspec-parameterized/pull/44 85 | - https://github.com/tomykaira/rspec-parameterized/issues/48 86 | 87 | ## [v0.4.0](https://github.com/tomykaira/rspec-parameterized/tree/v0.4.0) (2017-06-13) 88 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.3.2...v0.4.0) 89 | 90 | **Merged pull requests:** 91 | 92 | - Verbose test syntax [\#42](https://github.com/tomykaira/rspec-parameterized/pull/42) ([aliaksandr-martsinovich](https://github.com/aliaksandr-martsinovich)) 93 | - Customizable description [\#41](https://github.com/tomykaira/rspec-parameterized/pull/41) ([aliaksandr-martsinovich](https://github.com/aliaksandr-martsinovich)) 94 | 95 | ## [v0.3.2](https://github.com/tomykaira/rspec-parameterized/tree/v0.3.2) (2016-12-26) 96 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.3.1...v0.3.2) 97 | 98 | **Merged pull requests:** 99 | 100 | - Fix deprecation warning on ruby 2.4.0 [\#40](https://github.com/tomykaira/rspec-parameterized/pull/40) ([sue445](https://github.com/sue445)) 101 | - Add release note for v0.3.1 [\#39](https://github.com/tomykaira/rspec-parameterized/pull/39) ([sue445](https://github.com/sue445)) 102 | - Add rubygems version badge [\#38](https://github.com/tomykaira/rspec-parameterized/pull/38) ([sue445](https://github.com/sue445)) 103 | 104 | ## [v0.3.1](https://github.com/tomykaira/rspec-parameterized/tree/v0.3.1) (2016-08-17) 105 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.3.0...v0.3.1) 106 | 107 | **Closed issues:** 108 | 109 | - Support "||" syntax [\#34](https://github.com/tomykaira/rspec-parameterized/issues/34) 110 | 111 | **Merged pull requests:** 112 | 113 | - Set the caller of `.with\_them` to metadata of ExampleGroup [\#37](https://github.com/tomykaira/rspec-parameterized/pull/37) ([nalabjp](https://github.com/nalabjp)) 114 | - Add homepage url in gemspec [\#33](https://github.com/tomykaira/rspec-parameterized/pull/33) ([sue445](https://github.com/sue445)) 115 | - Tweak travis setting [\#32](https://github.com/tomykaira/rspec-parameterized/pull/32) ([sue445](https://github.com/sue445)) 116 | - Generate CHANGELOG [\#31](https://github.com/tomykaira/rspec-parameterized/pull/31) ([sue445](https://github.com/sue445)) 117 | 118 | ## [v0.3.0](https://github.com/tomykaira/rspec-parameterized/tree/v0.3.0) (2016-02-22) 119 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.2.0...v0.3.0) 120 | 121 | **Closed issues:** 122 | 123 | - Usage of variables in testcase name [\#27](https://github.com/tomykaira/rspec-parameterized/issues/27) 124 | - Remove `where\_table` method, when release next version [\#24](https://github.com/tomykaira/rspec-parameterized/issues/24) 125 | - Release v0.2.0 [\#23](https://github.com/tomykaira/rspec-parameterized/issues/23) 126 | - UTF-8 is converted to ASCII8BIT through sourcify [\#5](https://github.com/tomykaira/rspec-parameterized/issues/5) 127 | - where\_table does not work with proc [\#4](https://github.com/tomykaira/rspec-parameterized/issues/4) 128 | 129 | **Merged pull requests:** 130 | 131 | - Enable to browse parameter values in with\_them block [\#30](https://github.com/tomykaira/rspec-parameterized/pull/30) ([joker1007](https://github.com/joker1007)) 132 | - Remove unnecessary methods [\#29](https://github.com/tomykaira/rspec-parameterized/pull/29) ([joker1007](https://github.com/joker1007)) 133 | - Remove `where\_table` [\#28](https://github.com/tomykaira/rspec-parameterized/pull/28) ([joker1007](https://github.com/joker1007)) 134 | 135 | ## [v0.2.0](https://github.com/tomykaira/rspec-parameterized/tree/v0.2.0) (2015-09-17) 136 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.1.3...v0.2.0) 137 | 138 | **Merged pull requests:** 139 | 140 | - allow hash arguments [\#22](https://github.com/tomykaira/rspec-parameterized/pull/22) ([takkanm](https://github.com/takkanm)) 141 | - Update README to use expect syntax. [\#21](https://github.com/tomykaira/rspec-parameterized/pull/21) ([JunichiIto](https://github.com/JunichiIto)) 142 | 143 | ## [v0.1.3](https://github.com/tomykaira/rspec-parameterized/tree/v0.1.3) (2015-02-13) 144 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.1.2...v0.1.3) 145 | 146 | **Closed issues:** 147 | 148 | - rspec-parameterized-0.1.1.gem is broken [\#18](https://github.com/tomykaira/rspec-parameterized/issues/18) 149 | 150 | **Merged pull requests:** 151 | 152 | - Accept nil/boolean for 1st column [\#20](https://github.com/tomykaira/rspec-parameterized/pull/20) ([ryonext](https://github.com/ryonext)) 153 | - Update travis config [\#19](https://github.com/tomykaira/rspec-parameterized/pull/19) ([joker1007](https://github.com/joker1007)) 154 | 155 | ## [v0.1.2](https://github.com/tomykaira/rspec-parameterized/tree/v0.1.2) (2014-09-04) 156 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.1.1...v0.1.2) 157 | 158 | **Merged pull requests:** 159 | 160 | - Remove trailing '\>' character from TableSyntax [\#17](https://github.com/tomykaira/rspec-parameterized/pull/17) ([joker1007](https://github.com/joker1007)) 161 | - \[Suggest\] Where table syntax by Refinement [\#16](https://github.com/tomykaira/rspec-parameterized/pull/16) ([joker1007](https://github.com/joker1007)) 162 | 163 | ## [v0.1.1](https://github.com/tomykaira/rspec-parameterized/tree/v0.1.1) (2014-05-16) 164 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.1.0...v0.1.1) 165 | 166 | **Merged pull requests:** 167 | 168 | - Support RSpec3 [\#15](https://github.com/tomykaira/rspec-parameterized/pull/15) ([joker1007](https://github.com/joker1007)) 169 | 170 | ## [v0.1.0](https://github.com/tomykaira/rspec-parameterized/tree/v0.1.0) (2014-04-06) 171 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.0.9...v0.1.0) 172 | 173 | **Merged pull requests:** 174 | 175 | - Fix AST manipulation, for remove sourcify [\#14](https://github.com/tomykaira/rspec-parameterized/pull/14) ([joker1007](https://github.com/joker1007)) 176 | - Clear "already initialized constant Regexp::ENC\_XXX" warnings. [\#13](https://github.com/tomykaira/rspec-parameterized/pull/13) ([saturday06](https://github.com/saturday06)) 177 | 178 | ## [v0.0.9](https://github.com/tomykaira/rspec-parameterized/tree/v0.0.9) (2013-07-29) 179 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.0.8...v0.0.9) 180 | 181 | **Merged pull requests:** 182 | 183 | - Update rspec to v2.14 [\#12](https://github.com/tomykaira/rspec-parameterized/pull/12) ([joker1007](https://github.com/joker1007)) 184 | 185 | ## [v0.0.8](https://github.com/tomykaira/rspec-parameterized/tree/v0.0.8) (2013-05-16) 186 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.0.7...v0.0.8) 187 | 188 | **Closed issues:** 189 | 190 | - Please support rspec-rails 2.12 [\#9](https://github.com/tomykaira/rspec-parameterized/issues/9) 191 | 192 | **Merged pull requests:** 193 | 194 | - rspec: 2.12.0 -\> 2.13.0 [\#10](https://github.com/tomykaira/rspec-parameterized/pull/10) ([sue445](https://github.com/sue445)) 195 | 196 | ## [v0.0.7](https://github.com/tomykaira/rspec-parameterized/tree/v0.0.7) (2012-11-13) 197 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.0.6...v0.0.7) 198 | 199 | ## [v0.0.6](https://github.com/tomykaira/rspec-parameterized/tree/v0.0.6) (2012-09-24) 200 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.0.5...v0.0.6) 201 | 202 | **Merged pull requests:** 203 | 204 | - Fix where scope, in order to use let method and matcher in where blocks [\#7](https://github.com/tomykaira/rspec-parameterized/pull/7) ([joker1007](https://github.com/joker1007)) 205 | 206 | ## [v0.0.5](https://github.com/tomykaira/rspec-parameterized/tree/v0.0.5) (2012-08-22) 207 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.0.4...v0.0.5) 208 | 209 | ## [v0.0.4](https://github.com/tomykaira/rspec-parameterized/tree/v0.0.4) (2012-08-20) 210 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.0.3...v0.0.4) 211 | 212 | **Merged pull requests:** 213 | 214 | - Update to rspec 2.11.0 [\#6](https://github.com/tomykaira/rspec-parameterized/pull/6) ([mfolnovic](https://github.com/mfolnovic)) 215 | 216 | ## [v0.0.3](https://github.com/tomykaira/rspec-parameterized/tree/v0.0.3) (2012-05-24) 217 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.0.2...v0.0.3) 218 | 219 | **Closed issues:** 220 | 221 | - Where cannot be after with\_them [\#1](https://github.com/tomykaira/rspec-parameterized/issues/1) 222 | 223 | **Merged pull requests:** 224 | 225 | - fix params.inspect for document format. use Hash and Proc soucify. [\#3](https://github.com/tomykaira/rspec-parameterized/pull/3) ([joker1007](https://github.com/joker1007)) 226 | - fix where\_table method comment. method name was "where". [\#2](https://github.com/tomykaira/rspec-parameterized/pull/2) ([joker1007](https://github.com/joker1007)) 227 | 228 | ## [v0.0.2](https://github.com/tomykaira/rspec-parameterized/tree/v0.0.2) (2012-05-22) 229 | [Full Changelog](https://github.com/tomykaira/rspec-parameterized/compare/v0.0.1...v0.0.2) 230 | 231 | ## [v0.0.1](https://github.com/tomykaira/rspec-parameterized/tree/v0.0.1) (2012-05-20) 232 | 233 | 234 | \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* 235 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in rspec-parameterized.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 tomykaira 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RSpec::Parameterized [![Gem Version](https://badge.fury.io/rb/rspec-parameterized.svg)](https://badge.fury.io/rb/rspec-parameterized) ![rspec](https://github.com/tomykaira/rspec-parameterized/actions/workflows/rspec.yml/badge.svg) 2 | 3 | Support simple parameterized test syntax in rspec. 4 | 5 | ```ruby 6 | # Nested Array Style 7 | describe "plus" do 8 | where(:a, :b, :answer) do 9 | [ 10 | [1 , 2 , 3], 11 | [5 , 8 , 13], 12 | [0 , 0 , 0] 13 | ] 14 | end 15 | 16 | with_them do 17 | it "should do additions" do 18 | expect(a + b).to eq answer 19 | end 20 | end 21 | 22 | with_them do 23 | # Can browse parameters via `params` method in with_them block 24 | # Can browse all parameters via `all_params` method in with_them block 25 | it "#{params[:a]} + #{params[:b]} == #{params[:answer]}" do 26 | expect(a + b).to eq answer 27 | end 28 | end 29 | end 30 | 31 | # Hash and Array Style 32 | # Given parameters is each value combinations 33 | # On this case 34 | # [ 35 | # [1, 5, 2], 36 | # [1, 5, 4], 37 | # [1, 7, 2], 38 | # [1, 7, 4], 39 | # [1, 9, 2], 40 | # [1, 9, 4], 41 | # [3, 5, 2], 42 | # [3, 5, 4], 43 | # [3, 7, 2], 44 | # [3, 7, 4], 45 | # [3, 9, 2], 46 | # [3, 9, 4] 47 | # ] 48 | describe "Hash arguments" do 49 | where(a: [1, 3], b: [5, 7, 9], c: [2, 4]) 50 | 51 | with_them do 52 | it "sums is even" do 53 | expect(a + b + c).to be_even 54 | end 55 | end 56 | end 57 | 58 | # Table Syntax Style (like Groovy spock) 59 | # Need ruby-2.1 or later 60 | describe "plus" do 61 | using RSpec::Parameterized::TableSyntax 62 | 63 | where(:a, :b, :answer) do 64 | 1 | 2 | 3 65 | 5 | 8 | 13 66 | 0 | 0 | 0 67 | end 68 | 69 | with_them do 70 | it "should do additions" do 71 | expect(a + b).to eq answer 72 | end 73 | end 74 | end 75 | 76 | # Verbose Syntax 77 | # For complex inputs or if you just want to be super explicit 78 | describe "Verbose syntax" do 79 | where do 80 | { 81 | "positive integers" => { 82 | a: 1, 83 | b: 2, 84 | answer: 3, 85 | }, 86 | "negative_integers" => { 87 | a: -1, 88 | b: -2, 89 | answer: -3, 90 | }, 91 | "mixed_integers" => { 92 | a: 3, 93 | b: -3, 94 | answer: 0, 95 | }, 96 | } 97 | end 98 | 99 | with_them do 100 | it "should do additions" do 101 | expect(a + b).to eq answer 102 | end 103 | end 104 | end 105 | 106 | # It's also possible to override each combination name using magic variable :case_name 107 | # Output: 108 | # Custom names for regular syntax 109 | # positive integers 110 | # should do additions 111 | # negative integers 112 | # should do additions 113 | # mixed integers 114 | # should do additions 115 | describe "Custom names for regular syntax" do 116 | where(:case_name, :a, :b, :answer) do 117 | [ 118 | ["positive integers", 6, 2, 8], 119 | ["negative integers", -1, -2, -3], 120 | ["mixed integers", -5, 3, -2], 121 | ] 122 | end 123 | 124 | with_them do 125 | it "should do additions" do 126 | expect(a + b).to eq answer 127 | end 128 | end 129 | end 130 | 131 | # Or :case_names lambda for hash syntax 132 | # Output: 133 | # Custom naming for hash syntax 134 | # 1 + 5 + 2 135 | # sum is even 136 | # 1 + 5 + 4 137 | # sum is even 138 | # 1 + 7 + 2 139 | # sum is even 140 | # ... 141 | describe "Custom naming for hash syntax" do 142 | where(case_names: ->(a, b, c){"#{a} + #{b} + #{c}"}, a: [1, 3], b: [5, 7, 9], c: [2, 4]) 143 | 144 | with_them do 145 | it "sum is even" do 146 | expect(a + b + c).to be_even 147 | end 148 | end 149 | end 150 | 151 | # Use ref(:symbol) to use let/let! defined variables in the where block 152 | # Use lazy when you want to create let/let! variables after the where block 153 | # 154 | # Failures will be more readable in the future - https://github.com/tomykaira/rspec-parameterized/pull/65 155 | describe "lazy and ref types" do 156 | let(:one) { 1 } 157 | let(:four) { 4 } 158 | 159 | where(:a, :b, :result) do 160 | [ 161 | [ref(:one), ref(:four), lazy { two + three }] 162 | ] 163 | end 164 | 165 | with_them do 166 | context "use let after where block" do 167 | let(:two) { 2 } 168 | let(:three) { 3 } 169 | 170 | it 'should equal 5' do 171 | expect(a + b).to eq result 172 | end 173 | end 174 | end 175 | end 176 | ``` 177 | 178 | I was inspired by [udzura's mock](https://gist.github.com/1881139). 179 | 180 | ## Support Versions 181 | 182 | Ruby-2.6.0 or later. 183 | 184 | ## Installation 185 | ```ruby 186 | group :test do 187 | gem "rspec-parameterized", ">= 1.0.0" 188 | end 189 | ``` 190 | 191 | ## Usage 192 | 193 | Require `rspec-parameterized` from your `spec_helper.rb`. 194 | 195 | require 'rspec-parameterized' 196 | 197 | Follow the sample spec above. 198 | 199 | Arguments given to `with_them` is directly passed to `describe`. You can specify `:pending`, `:focus`, etc. here. 200 | 201 | ## Contributing 202 | 203 | 1. Fork it 204 | 2. Create your feature branch (`git checkout -b my-new-feature`) 205 | 3. Commit your changes (`git commit -am 'Added some feature'`) 206 | 4. Push to the branch (`git push origin my-new-feature`) 207 | 5. Create new Pull Request 208 | 209 | ## Also see 210 | 211 | * https://github.com/rspec-parameterized/rspec-parameterized-table_syntax 212 | * https://github.com/rspec-parameterized/rspec-parameterized-core 213 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | require "bundler/gem_tasks" 3 | 4 | task :default => [:spec] 5 | begin 6 | require 'rspec/core/rake_task' 7 | RSpec::Core::RakeTask.new(:spec) do |spec| 8 | spec.pattern = 'spec/**/*_spec.rb' 9 | spec.rspec_opts = ['-c -f d'] 10 | end 11 | end 12 | 13 | namespace :spec do 14 | %w(rspec2 rspec3.3 rspec3.4).each do |gemfile| 15 | desc "Run Tests by #{gemfile}.gemfile" 16 | task gemfile do 17 | Bundler.with_clean_env do 18 | sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle install --path .bundle" 19 | sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle exec rake -t spec" 20 | end 21 | end 22 | end 23 | 24 | desc "Run All Tests" 25 | task :all do 26 | %w(rspec2 rspec3.3 rspec3.4).each do |gemfile| 27 | Rake::Task["spec:#{gemfile}"].invoke 28 | end 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /UPGRADING.md: -------------------------------------------------------------------------------- 1 | # v1.0 2 | Moved all implements to https://github.com/rspec-parameterized/rspec-parameterized-core and https://github.com/rspec-parameterized/rspec-parameterized-table_syntax 3 | 4 | For v0.x users, there is basically no need to do anything other than `bundle update`. 5 | 6 | If you are not using `RSpec::Parameterized::TableSyntax`, you can write `rspec-parameterized-core` instead of `rspec-parameterized` in your `Gemfile` to reduce the dependency. (`rspec-parameterized-table_syntax` includes dependency on native extension...) 7 | 8 | e.g. 9 | 10 | ```ruby 11 | # Before 12 | gem "rspec-parameterized" 13 | 14 | # After 15 | gem "rspec-parameterized-core" 16 | ``` 17 | -------------------------------------------------------------------------------- /lib/rspec-parameterized.rb: -------------------------------------------------------------------------------- 1 | require 'rspec/parameterized' 2 | -------------------------------------------------------------------------------- /lib/rspec/parameterized.rb: -------------------------------------------------------------------------------- 1 | require "rspec/parameterized/version" 2 | require "rspec/parameterized/core" 3 | require "rspec/parameterized/table_syntax" 4 | 5 | module RSpec 6 | module Parameterized 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/rspec/parameterized/version.rb: -------------------------------------------------------------------------------- 1 | module RSpec 2 | module Parameterized 3 | VERSION = "2.0.0" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /rspec-parameterized.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | require File.expand_path('../lib/rspec/parameterized/version', __FILE__) 3 | 4 | Gem::Specification.new do |gem| 5 | gem.authors = ["tomykaira"] 6 | gem.email = ["tomykaira@gmail.com"] 7 | gem.description = %q{RSpec::Parameterized supports simple parameterized test syntax in rspec.} 8 | gem.summary = %q{RSpec::Parameterized supports simple parameterized test syntax in rspec. 9 | I was inspired by [udzura's mock](https://gist.github.com/1881139).} 10 | gem.homepage = "https://github.com/tomykaira/rspec-parameterized" 11 | 12 | gem.metadata["rubygems_mfa_required"] = "true" 13 | gem.license = "MIT" 14 | 15 | gem.add_dependency('rspec-parameterized-core', '>= 2', '< 3') 16 | gem.add_dependency('rspec-parameterized-table_syntax', '>= 2', '< 3') 17 | 18 | gem.add_development_dependency('rake', '>= 12.0.0') 19 | 20 | gem.files = `git ls-files`.split($\) 21 | gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } 22 | gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) 23 | gem.name = "rspec-parameterized" 24 | gem.require_paths = ["lib"] 25 | gem.version = RSpec::Parameterized::VERSION 26 | end 27 | -------------------------------------------------------------------------------- /spec/parametarized_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path(File.dirname(__FILE__) + '/spec_helper') 2 | 3 | # RSpec::Parameterized 4 | # Sample 5 | # plus 6 | # [1, 2, 3] 7 | # should do additions 8 | # [5, 8, 13] 9 | # should do additions 10 | # [0, 0, 0] 11 | # should do additions 12 | 13 | describe RSpec::Parameterized do 14 | describe "where and with_them" do 15 | where(:a, :b, :answer) do 16 | [ 17 | [1 , 2 , 3], 18 | [5 , 8 , 13], 19 | [0 , 0 , 0] 20 | ] 21 | end 22 | 23 | with_them do 24 | it "should do additions" do 25 | expect(a + b).to eq answer 26 | end 27 | end 28 | 29 | with_them do 30 | it "#{params[:a]} + #{params[:b]} == #{params[:answer]}" do 31 | expect(a + b).to eq answer 32 | end 33 | end 34 | 35 | with_them pending: "PENDING" do 36 | it "should do additions" do 37 | expect(a + b).to == answer 38 | end 39 | end 40 | end 41 | 42 | describe "lambda parameter" do 43 | where(:a, :b, :answer) do 44 | [ 45 | [1 , 2 , -> {should == 3}], 46 | [5 , 8 , -> {should == 13}], 47 | [0 , 0 , -> {should == 0}] 48 | ] 49 | end 50 | 51 | with_them do 52 | subject {a + b} 53 | it "should do additions" do 54 | self.instance_exec(&answer) 55 | end 56 | end 57 | end 58 | 59 | describe "Hash arguments" do 60 | where(a: [1, 3], b: [5, 7, 9], c: [2, 4]) 61 | 62 | with_them do 63 | it "sums is even" do 64 | expect(a + b + c).to be_even 65 | end 66 | end 67 | end 68 | 69 | describe "Verbose syntax" do 70 | where do 71 | { 72 | "positive integers" => { 73 | a: 1, 74 | b: 2, 75 | answer: 3, 76 | }, 77 | "negative_integers" => { 78 | a: -1, 79 | b: -2, 80 | answer: -3, 81 | }, 82 | "mixed_integers" => { 83 | a: 3, 84 | b: -3, 85 | answer: 0, 86 | }, 87 | } 88 | end 89 | 90 | with_them do 91 | it "should do additions" do 92 | expect(a + b).to eq answer 93 | end 94 | 95 | it "should have custom name" do |example| 96 | expect(example.metadata[:example_group][:description]).to eq case_name 97 | end 98 | end 99 | 100 | context "lambda parameter" do 101 | where do 102 | { 103 | "integers" => { 104 | a: 1, 105 | b: 2, 106 | answer: -> {expect(subject).to eq 3}, 107 | }, 108 | "strings" => { 109 | a: "hello ", 110 | b: "world", 111 | answer: -> {expect(subject).to include "lo wo"}, 112 | }, 113 | "arrays" => { 114 | a: [1, 2, 3], 115 | b: [4, 5, 6], 116 | answer: -> {expect(subject.size).to eq 6} 117 | } 118 | } 119 | end 120 | 121 | with_them do 122 | subject {a + b} 123 | it "should do additions" do 124 | self.instance_exec(&answer) 125 | end 126 | 127 | it "should have custom name" do |example| 128 | expect(example.metadata[:example_group][:description]).to eq(case_name) 129 | end 130 | end 131 | end 132 | end 133 | 134 | describe "Custom test case name" do 135 | context "when regular arguments" do 136 | where(:case_name, :a, :b, :answer) do 137 | [ 138 | ["positive integers", 6, 2, 8], 139 | ["negative integers", -1, -2, -3], 140 | [ "mixed integers", -5, 3, -2], 141 | ] 142 | end 143 | 144 | with_them do 145 | it "should do additions" do 146 | expect(a + b).to eq answer 147 | end 148 | 149 | it "should have custom test name" do |example| 150 | expect(example.metadata[:example_group][:description]).to eq case_name 151 | end 152 | end 153 | end 154 | 155 | context "when hash arguments" do 156 | where(case_names: ->(a, b, c){"#{a} + #{b} + #{c}"}, a: [1, 3], b: [5, 7, 9], c: [2, 4]) 157 | 158 | with_them do 159 | it "sum is even" do 160 | expect(a + b + c).to be_even 161 | end 162 | 163 | it "should have custom names" do |example| 164 | expect(example.metadata[:example_group][:description]).to include "+" 165 | end 166 | end 167 | end 168 | 169 | if RUBY_VERSION >= "2,1" 170 | context "when arguments are separated with pipe (using TableSyntax)" do 171 | using RSpec::Parameterized::TableSyntax 172 | 173 | where(:case_name, :a, :b, :answer) do 174 | "integers" | 1 | 2 | 3 175 | "strings" | "hello " | "world" | "hello world" 176 | "arrays" | [1, 2, 3] | [4, 5, 6] | [1, 2, 3, 4, 5, 6] 177 | "giant numbers" | 100000000000000000000 | 100000000000000000000 | 200000000000000000000 178 | end 179 | 180 | with_them do 181 | it "a plus b is answer" do 182 | expect(a + b).to eq answer 183 | end 184 | 185 | it "should have custom test name" do |example| 186 | expect(example.metadata[:example_group][:description]).to eq case_name 187 | end 188 | end 189 | end 190 | end 191 | 192 | end 193 | 194 | describe "ref" do 195 | context 'simple usecase' do 196 | let(:foo) { 1 } 197 | 198 | where(:value, :answer) do 199 | [ 200 | [ref(:foo), 1], 201 | ] 202 | end 203 | 204 | with_them do 205 | it "let variable in same example group can be used" do 206 | expect(value).to eq answer 207 | end 208 | 209 | context "override let varibale" do 210 | let(:foo) { 3 } 211 | 212 | it "can override let variable" do 213 | expect(value).to eq 3 214 | end 215 | end 216 | end 217 | end 218 | 219 | context "recursive usecase" do 220 | let(:foo) { 1 } 221 | 222 | where(:value, :answer) do 223 | [ 224 | [[ref(:foo), 2], [1, 2]], 225 | ] 226 | end 227 | 228 | with_them do 229 | it "let variable in same example group can be used" do 230 | expect(value).to eq answer 231 | end 232 | 233 | context "override let varibale" do 234 | let(:foo) { 3 } 235 | 236 | it "can override let variable" do 237 | expect(value).to eq [3, 2] 238 | end 239 | end 240 | end 241 | end 242 | end 243 | 244 | describe "lazy" do 245 | context "simple usecase" do 246 | let(:one) { 1 } 247 | let(:four) { 4 } 248 | 249 | where(:a, :b, :answer) do 250 | [ 251 | [ref(:one), ref(:four), lazy { two + three }], 252 | ] 253 | end 254 | 255 | with_them do 256 | context "define two and three after where block" do 257 | let(:two) { 2 } 258 | let(:three) { 3 } 259 | 260 | it "should do additions" do 261 | expect(a + b).to eq answer 262 | end 263 | end 264 | end 265 | end 266 | 267 | context 'recursive usecase' do 268 | let(:one) { 1 } 269 | let(:four) { 4 } 270 | 271 | where(:a, :b, :answer) do 272 | [ 273 | [ref(:one), ref(:four), { result: lazy { two + three } }], 274 | ] 275 | end 276 | 277 | with_them do 278 | context "define two and three after where block" do 279 | let(:two) { 2 } 280 | let(:three) { 3 } 281 | 282 | it "should do additions" do 283 | expect(a + b).to eq answer[:result] 284 | end 285 | end 286 | end 287 | end 288 | end 289 | 290 | if RUBY_VERSION >= "2.1" 291 | describe "table separated with pipe (using TableSyntax)" do 292 | using RSpec::Parameterized::TableSyntax 293 | 294 | where(:a, :b, :answer) do 295 | 1 | 2 | 3 296 | "hello " | "world" | "hello world" 297 | [1, 2, 3] | [4, 5, 6] | [1, 2, 3, 4, 5, 6] 298 | 100000000000000000000 | 100000000000000000000 | 200000000000000000000 299 | end 300 | 301 | with_them do 302 | it "a plus b is answer" do 303 | expect(a + b).to eq answer 304 | end 305 | end 306 | end 307 | 308 | describe "table separated with pipe and lambda parameter (using TableSyntax)" do 309 | using RSpec::Parameterized::TableSyntax 310 | 311 | where(:a, :b, :matcher) do 312 | 1 | 2 | -> { eq(3) } 313 | "hello " | "world" | -> { eq("hello world") } 314 | [1, 2, 3] | [4, 5, 6] | -> { be_a(Array) } 315 | 100000000000000000000 | 100000000000000000000 | -> { eq(200000000000000000000) } 316 | end 317 | 318 | with_them do 319 | it "a plus b is answer" do 320 | expect(a + b).to instance_exec(&matcher) 321 | end 322 | end 323 | end 324 | end 325 | 326 | context "when the where block is after with_them" do 327 | with_them do 328 | it "should do additions" do 329 | expect(a + b).to eq answer 330 | end 331 | end 332 | 333 | with_them do 334 | subject { a } 335 | it { should be_a Numeric } 336 | end 337 | 338 | where(:a, :b, :answer) do 339 | [ 340 | [1 , 2 , 3], 341 | [5 , 8 , 13], 342 | [0 , 0 , 0] 343 | ] 344 | end 345 | end 346 | 347 | context "when the where block is between with_thems" do 348 | with_them do 349 | it "should do additions" do 350 | expect(a + b).to eq answer 351 | end 352 | end 353 | 354 | where(:a, :b, :answer) do 355 | [ 356 | [1 , 2 , 3], 357 | [5 , 8 , 13], 358 | [0 , 0 , 0] 359 | ] 360 | end 361 | 362 | with_them do 363 | subject { a } 364 | it { should be_a Numeric } 365 | end 366 | end 367 | 368 | context "when the where has only one parameter to be set" do 369 | where(:x) do 370 | [1, 2, 3] 371 | end 372 | 373 | with_them do 374 | it 'can take an array of elements' do 375 | expect(x).to eq x 376 | end 377 | end 378 | end 379 | 380 | if RUBY_VERSION >= "2.1" 381 | context "when the table has only a row (using TableSyntax)" do 382 | using RSpec::Parameterized::TableSyntax 383 | 384 | where(:a, :b, :answer) do 385 | 1 | 2 | 3 386 | end 387 | 388 | with_them do 389 | it "a plus b is answer" do 390 | expect(a + b).to eq answer 391 | end 392 | end 393 | end 394 | context "when 1st column is nil or true or false" do 395 | using RSpec::Parameterized::TableSyntax 396 | where(:a, :result) do 397 | nil | nil 398 | false | false 399 | true | true 400 | end 401 | 402 | with_them do 403 | it "a is result" do 404 | expect(a).to be result 405 | end 406 | end 407 | end 408 | end 409 | 410 | context "when the where has let variables, defined by parent example group" do 411 | describe "parent (define let)" do 412 | let(:five) { 5 } 413 | let(:eight) { 8 } 414 | 415 | describe "child 1" do 416 | where(:a, :b, :answer) do 417 | [ 418 | [1 , 2 , 3], 419 | [five , eight , 13], 420 | ] 421 | end 422 | 423 | with_them do 424 | it "a plus b is answer" do 425 | expect(a + b).to eq answer 426 | end 427 | end 428 | end 429 | 430 | if RUBY_VERSION >= "2.1" 431 | describe "child 3 (Using TableSyntax)" do 432 | using RSpec::Parameterized::TableSyntax 433 | 434 | where(:a, :b, :answer) do 435 | 1 | 2 | 3 436 | five | eight | 13 437 | end 438 | 439 | with_them do 440 | it "a plus b is answer" do 441 | expect(a + b).to eq answer 442 | end 443 | end 444 | end 445 | end 446 | 447 | let(:eq_matcher) { eq(13) } 448 | describe "child 3 (use matcher)" do 449 | where(:a, :b, :matcher) do 450 | [ 451 | [1 , 2 , eq(3) ], 452 | [five , eight , eq_matcher], 453 | ] 454 | end 455 | 456 | with_them do 457 | it "a plus b is answer" do 458 | expect(a + b).to matcher 459 | end 460 | end 461 | end 462 | end 463 | end 464 | end 465 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'rspec-parameterized' 2 | 3 | RSpec.configure do |config| 4 | config.run_all_when_everything_filtered = true 5 | config.filter_run :current 6 | end 7 | --------------------------------------------------------------------------------