Skip to content

Commit

Permalink
ensure shared examples name is marshaled as string
Browse files Browse the repository at this point in the history
  • Loading branch information
bdvineti committed Mar 2, 2021
1 parent d71f716 commit 7eeb2b7
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
26 changes: 26 additions & 0 deletions features/rspec.feature
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,29 @@ Feature: rspec task
"""
# ./spec/spec_spec.rb:2:in `block (2 levels) in <top (required)>'
"""

Scenario: it behaves like
Given the following spec:
"""
class Rick
def drunk?
true
end
end
class PickleRick < Rick
end
shared_examples_for Rick do
it('drinks') { expect(subject).to be_drunk }
end
describe PickleRick do
it_behaves_like Rick
end
"""
When I run flatware with "rspec"
Then the output contains the following:
"""
1 example, 0 failures
"""
15 changes: 14 additions & 1 deletion lib/flatware/rspec/marshalable/example.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module Flatware
module RSpec
module Marshalable
require 'flatware/rspec/marshalable/shared_group_inclusion_backtrace'

##
# a subset of the rspec example interface that can traverse drb
Example = Struct.new(
Expand All @@ -16,10 +18,21 @@ def initialize(rspec_example)
rspec_example.public_send(attribute)
end)

@metadata = rspec_example.metadata.slice(:extra_failure_lines, :shared_group_inclusion_backtrace)
@metadata = marshalable_metadata(rspec_example.metadata)
end

attr_reader :metadata

private

def marshalable_metadata(rspec_metadata)
rspec_metadata.slice(:extra_failure_lines).tap do |metadata|
if (backtraces = rspec_metadata[:shared_group_inclusion_backtrace])
metadata[:shared_group_inclusion_backtrace] =
backtraces.map(&SharedGroupInclusionBacktrace.method(:from_rspec))
end
end
end
end
end
end
Expand Down
11 changes: 11 additions & 0 deletions lib/flatware/rspec/marshalable/shared_group_inclusion_backtrace.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Flatware
module RSpec
module Marshalable
class SharedGroupInclusionBacktrace < ::RSpec::Core::SharedExampleGroupInclusionStackFrame
def self.from_rspec(backtrace)
new(backtrace.shared_group_name.to_s, backtrace.inclusion_location)
end
end
end
end
end

0 comments on commit 7eeb2b7

Please sign in to comment.