diff --git a/.rubocop.yml b/.rubocop.yml index 78f0948..17a300d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,6 +4,9 @@ AllCops: TargetRubyVersion: 2.6 NewCops: enable +Gemspec/DevelopmentDependencies: + EnforcedStyle: gemspec + Layout/LineLength: Max: 100 diff --git a/README.md b/README.md index 65e821e..7606b38 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,10 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). +## Alternatives + +* [rspec-parameterized](https://github.com/tomykaira/rspec-parameterized) + ## Elsewhere on the web Links to other places on the web where this projects exists: diff --git a/Rakefile b/Rakefile index 18bf4e0..74335ac 100644 --- a/Rakefile +++ b/Rakefile @@ -2,6 +2,8 @@ require 'bundler/gem_tasks' require 'rspec/core/rake_task' +require 'cucumber' +require 'cucumber/rake/task' require 'rubocop/rake_task' require 'bundler/audit/task' require 'pathname' @@ -12,6 +14,10 @@ RSpec::Core::RakeTask.new(:spec) do |task| task.rspec_opts = '--warnings' end +Cucumber::Rake::Task.new do |task| + task.cucumber_opts = '--publish-quiet' +end + RuboCop::RakeTask.new(:rubocop) do |task| rubocop_report_pathname = Pathname(Rake.application.original_dir).join('tmp', 'rubocop.txt') @@ -47,4 +53,4 @@ task 'bundle:outdated' do sh("bundle outdated --only-explicit | tee #{bundle_outdated_report_pathname}") end -task default: %i[spec rubocop bundle:audit license_finder] +task default: %i[spec cucumber rubocop bundle:audit license_finder] diff --git a/features/step_definitions/additional_cli_steps.rb b/features/step_definitions/additional_cli_steps.rb new file mode 100644 index 0000000..434a186 --- /dev/null +++ b/features/step_definitions/additional_cli_steps.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +When /^I run rspec( with the documentation option)?$/ do |documentation| + rspec_its_gem_location = File.expand_path('../../../lib/rspec/tabular', __FILE__) + require_option = "--require #{rspec_its_gem_location}" + format_option = documentation ? "--format documentation" : "" + rspec_command = ['rspec', require_option, format_option, 'example_spec.rb'].join(' ') + step "I run `#{rspec_command}`" +end diff --git a/features/support/env.rb b/features/support/env.rb new file mode 100644 index 0000000..751674f --- /dev/null +++ b/features/support/env.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +require 'aruba/cucumber' diff --git a/features/support/tabular.feature b/features/support/tabular.feature new file mode 100644 index 0000000..ede107c --- /dev/null +++ b/features/support/tabular.feature @@ -0,0 +1,65 @@ +# frozen_string_literal: true + +Feature: Specify examples as tables of inputs and expectations + +Scenario: A passing tabular spec + Given a file named "example_spec.rb" with: + """ruby + class TestModel + def method(value1, value2) + "result:#{value1}:#{value2}" + end + end + describe TestModel do + subject(:test_model) { described_class.new } + + describe '#method' do + subject { test_model.method(input1, input2) } + + inputs :input1, :input2 + it_with :value1, :value2, 'result:value1:value2' + it_with(:value3, :value4) { is_expected.to eq('result:value3:value4') } + + end + end + """ + When I run rspec with the documentation option + Then the output should contain: + """ + TestModel + #method + with {:input1=>:value1, :input2=>:value2} + is expected to eq "result:value1:value2" + with {:input1=>:value3, :input2=>:value4} + is expected to eq "result:value3:value4" + """ + +Scenario: A failing tabular spec + Given a file named "example_spec.rb" with: + """ruby + class TestModel + def method(value1, value2) + "result:#{value1}:#{value2}" + end + end + describe TestModel do + subject(:test_model) { described_class.new } + + describe '#method' do + subject { test_model.method(input1, input2) } + + inputs :input1, :input2 + it_with :value1, :value2, 'result:value1:foobar' + it_with(:value3, :value4) { is_expected.to eq('result:value3:deadbeef') } + end + end + """ + When I run rspec with the documentation option + Then the output should contain: + """ + Failure/Error: DEFAULT_FAILURE_NOTIFIER = lambda { |failure, _opts| raise failure } + """ + Then the output should contain: + """ + Failure/Error: it_with(:value3, :value4) { is_expected.to eq('result:value3:deadbeef') } + """ diff --git a/rspec-tabular.gemspec b/rspec-tabular.gemspec index d3ef141..993350b 100644 --- a/rspec-tabular.gemspec +++ b/rspec-tabular.gemspec @@ -27,7 +27,9 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency 'rspec-core', '>= 2.99.0' + spec.add_development_dependency 'aruba', '~> 2.0' spec.add_development_dependency 'bundler', '~> 2.0' + spec.add_development_dependency 'cucumber', '~> 8.0' spec.add_development_dependency 'rake', '~> 13.0' spec.add_development_dependency 'rspec', '~> 3.5'