### Update Gemfile: rspec-parameterized to rspec-parameterized-core Source: https://github.com/tomykaira/rspec-parameterized/blob/master/UPGRADING.md Shows the change in Gemfile syntax when moving from the main `rspec-parameterized` gem to the more focused `rspec-parameterized-core` gem. This is recommended for users not employing the table syntax feature to minimize dependencies. ```ruby # Before gem "rspec-parameterized" # After gem "rspec-parameterized-core" ``` -------------------------------- ### Installing RSpec::Parameterized Gem Source: https://github.com/tomykaira/rspec-parameterized/blob/master/README.md Provides the necessary command to add the `rspec-parameterized` gem to your project's Gemfile for testing. This ensures that the parameterized testing capabilities are available in your RSpec environment. ```ruby group :test do gem "rspec-parameterized", ">= 1.0.0" end ``` -------------------------------- ### Using `ref` and `lazy` for Parameterized Tests in RSpec Source: https://github.com/tomykaira/rspec-parameterized/blob/master/README.md Explains how to use `ref(:symbol)` to reference RSpec's `let` or `let!` defined variables within the `where` block, and `lazy` to define `let`/`let!` variables that are created after the `where` block. This allows for dynamic parameter generation. ```ruby describe "lazy and ref types" do let(:one) { 1 } let(:four) { 4 } where(:a, :b, :result) do [ [ref(:one), ref(:four), lazy { two + three }] ] end with_them do context "use let after where block" do let(:two) { 2 } let(:three) { 3 } it 'should equal 5' do expect(a + b).to eq result end end end end ``` -------------------------------- ### Verbose Syntax Parameterized Tests in RSpec Source: https://github.com/tomykaira/rspec-parameterized/blob/master/README.md Illustrates the verbose syntax for defining parameterized tests, which is suitable for complex inputs or when explicit definition is preferred. Parameters are provided as a hash where keys are descriptive names for test case groups. ```ruby describe "Verbose syntax" do where do { "positive integers" => { a: 1, b: 2, answer: 3, }, "negative_integers" => { a: -1, b: -2, answer: -3, }, "mixed_integers" => { a: 3, b: -3, answer: 0, }, } end with_them do it "should do additions" do expect(a + b).to eq answer end end end ``` -------------------------------- ### Hash and Array Style Parameterized Tests in RSpec Source: https://github.com/tomykaira/rspec-parameterized/blob/master/README.md Shows how to use a combination of hash and array syntax for defining test parameters. This style allows for more descriptive parameter names when defining them. It's useful for tests with multiple parameters that have specific meanings. ```ruby describe "Hash arguments" do where(a: [1, 3], b: [5, 7, 9], c: [2, 4]) with_them do it "sums is even" do expect(a + b + c).to be_even end end end ``` -------------------------------- ### Table Syntax Style Parameterized Tests in RSpec Source: https://github.com/tomykaira/rspec-parameterized/blob/master/README.md Implements parameterized tests using a table syntax, similar to Groovy's Spock framework. This requires Ruby 2.1 or later and is defined using `RSpec::Parameterized::TableSyntax`. It offers a concise way to define test data in a tabular format. ```ruby describe "plus" do using RSpec::Parameterized::TableSyntax where(:a, :b, :answer) do 1 | 2 | 3 5 | 8 | 13 0 | 0 | 0 end with_them do it "should do additions" do expect(a + b).to eq answer end end end ``` -------------------------------- ### Customizing Test Case Names in RSpec with RSpec::Parameterized Source: https://github.com/tomykaira/rspec-parameterized/blob/master/README.md Demonstrates how to customize the names of parameterized test cases. This can be done by including a `:case_name` symbol in the `where` block for regular array syntax or using a `case_names` lambda for hash syntax, improving test report readability. ```ruby describe "Custom names for regular syntax" do where(:case_name, :a, :b, :answer) do [ ["positive integers", 6, 2, 8], ["negative integers", -1, -2, -3], ["mixed integers", -5, 3, -2], ] end with_them do it "should do additions" do expect(a + b).to eq answer end end end ``` ```ruby describe "Custom naming for hash syntax" do where(case_names: ->(a, b, c){"#{a} + #{b} + #{c}"}, a: [1, 3], b: [5, 7, 9], c: [2, 4]) with_them do it "sum is even" do expect(a + b + c).to be_even end end end ``` -------------------------------- ### Nested Array Style Parameterized Tests in RSpec Source: https://github.com/tomykaira/rspec-parameterized/blob/master/README.md Demonstrates using nested arrays to define parameters for RSpec tests. Each inner array represents a set of parameters for a test case. The `where` and `with_them` methods are used to structure the parameterized tests. ```ruby describe "plus" do where(:a, :b, :answer) do [ [1 , 2 , 3], [5 , 8 , 13], [0 , 0 , 0] ] end with_them do it "should do additions" do expect(a + b).to eq answer end end with_them do # Can browse parameters via `params` method in with_them block # Can browse all parameters via `all_params` method in with_them block it "#{params[:a]} + #{params[:b]} == #{params[:answer]}" do expect(a + b).to eq answer end end end ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.