Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to fix the failure reporting #14

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ AllCops:
TargetRubyVersion: 2.6
NewCops: enable

Gemspec/DevelopmentDependencies:
EnforcedStyle: gemspec

Layout/LineLength:
Max: 100

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 7 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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')
Expand Down Expand Up @@ -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]
9 changes: 9 additions & 0 deletions features/step_definitions/additional_cli_steps.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

require 'aruba/cucumber'
65 changes: 65 additions & 0 deletions features/support/tabular.feature
Original file line number Diff line number Diff line change
@@ -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') }
"""
2 changes: 2 additions & 0 deletions rspec-tabular.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down