Skip to content
Simple parameterized testing with RSpec (a.k.a table tests)
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
bin
lib/rspec
spec
.gitignore
.rspec
.travis.yml
CHANGELOG.md
Gemfile
Gemfile.lock
LICENSE.txt
README.md
Rakefile
rspec-with_params.gemspec

README.md

RSpec::WithParams

Gem Version CircleCI

Simple parameterized testing (a.k.a table tests) with RSpec.

RSpec.describe "my complex business logic" do
  extend RSpec::WithParams::DSL

  with_params(
    [:today,        :schedule,    :expected_date],
    ["2019-06-05",  "weekly",     "2019-06-13"],
    ["2019-06-05",  "bi-weekly",  "2019-06-20"],
    ["2019-06-05",  "monthly",    "2019-07-13"],
  ) do
    it "determines the next appointment date" do
      result = NextAppointmentCalculator.new.process(today, schedule)
      expect(result).to eq expected_date
    end
  end
end

Output (with --format documentation):

my complex business logic
  given today -> "2019-06-05", schedule -> "weekly", expected_date -> "2019-06-13"
    determines the next appointment date
  given today -> "2019-06-05", schedule -> "monthly", expected_date -> "2019-06-20"
    determines the next appointment date
  given today -> "2019-06-05", schedule -> "bi-weekly", expected_date -> "2019-06-20"
    determines the next appointment date

Finished in 0.00136 seconds (files took 0.12486 seconds to load)
3 examples, 0 failures

Usage

# Gemfile

group :test do
  gem "rspec-with_params"
end

Extend specific test groups:

require "rspec/with_params/dsl"

RSpec.describe "my complex business logic" do
  extend RSpec::WithParams::DSL

  # examples...
end

Or configure RSpec globally:

require "rspec/with_params/dsl"

RSpec.configure do |config|
  config.extend(RSpec::WithParams::DSL)
end

Development

git clone git@github.com:odlp/rspec-with_params.git
cd rspec-with_params
bundle
bundle exec rake

Alternatives

License

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

You can’t perform that action at this time.