No release in over 3 years
Low commit activity in last 3 years
This rubygem does not have a description or summary.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Rspec::Parameterized::Context

Generate interfaces like RSpec::Parameterized to support parameterized testing that is evaluated in transaction.

Support Ruby 2.5 and later.

Installation

Add this line to your application's Gemfile:

gem 'rspec-parameterized-context'

Then add this lines to files under spec/support/

RSpec.configure do |config|
  config.extend RSpecParameterizedContext
end

Usage

Syntax

Provide interfaces like RSpec::Parameterized.

Pass where and with_them to parameterized method as one block and specify parameterized count as size keyword argument.

describe "Addition" do
  parameterized do
    where(:a, :b, :answer, size: 3) do
      [
        [1 , 2 , 3],
        [5 , 8 , 13],
        [0 , 0 , 0]
      ]
    end

    with_them do
      it do
        expect(a + b).to eq answer
      end
    end
  end
end

Feature

  • rspec-parameterized-context supports to evaluate block that given where method in transaction.
# Assume today is 2020/9/9
describe 'Evaluting block that given to where in transaction' do
  let(:now) { Date.new(2020, 1, 1) }
  # And travel to 2020/1/1
  before { travel_to(now) }

  parameterized do
    where(:current_on, size: 1) do
      [
        [Date.current],
      ]
    end

    with_them do
      it do
        # current_on is evaluated as 2020/1/1
        expect(current_on).to eq now
      end
    end
  end
end
  • You can run specific context by focus_index parameter
describe "Addition" do
  parameterized do
    where(:a, :b, :answer, size: 3, focus_index: 1) do
      [
        [1 , 2 , 3],
        [5 , 8 , 13], # will run only this context
        [0 , 0 , 0]
      ]
    end

    with_them do
      it do
        expect(a + b).to eq answer
      end
    end
  end
end

Contributing

  • Fork the project.
  • Create feature branch.
  • Commit and push.
  • Make sure to add tests for it.
  • Create pull request.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Rspec::Parameterized::Context project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.