Skip to content

Commit

Permalink
Solve deprecated warnings by changes RSpec 2 to 3.
Browse files Browse the repository at this point in the history
- `example.execution_result` became `Hash` to `RSpec::Core::Example::ExecutionResult`
- Key that get parent example group metadata changes `:parent_example_group`
  • Loading branch information
gongo committed Jul 30, 2014
1 parent 4a7890e commit ed01197
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 19 deletions.
51 changes: 39 additions & 12 deletions lib/turnip_formatter/scenario/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ def name
# @return [String] scenario status ('passed', 'failed' or 'pending')
#
def status
example.execution_result[:status]
execution_result.status.to_s
end

#
# @return [String] scenario run time
#
def run_time
example.execution_result[:run_time]
execution_result.run_time
end

def feature_info
Expand All @@ -56,7 +56,7 @@ def feature_info
end

def feature_name
example.example_group.metadata[:example_group][:example_group][:description]
parent_example_group[:description]
end

def tags
Expand All @@ -69,21 +69,48 @@ def example

protected

def validation
unless example.metadata.key?(:turnip_formatter)
@errors << 'has no steps information'
end
def validation
unless example.metadata.key?(:turnip_formatter)
@errors << 'has no steps information'
end
end

private

def feature_file_path
example.metadata[:file_path]
end
def feature_file_path
example.metadata[:file_path]
end

def raw_steps
example.metadata[:turnip_formatter][:steps]
def raw_steps
example.metadata[:turnip_formatter][:steps]
end

#
# @return [Hash] parent example group
#
def parent_example_group
if example.example_group.metadata.key?(:parent_example_group)
# RSpec 3
example.example_group.metadata[:parent_example_group]
else
# RSpec 2
example.example_group.metadata[:example_group][:example_group]
end
end

#
# @return [OpenStruct or ::RSpec::Core::Example::ExecutionResult]
#
def execution_result
@execution_result ||= case example.execution_result
when Hash
# RSpec 2
OpenStruct.new(example.execution_result)
when ::RSpec::Core::Example::ExecutionResult
# RSpec 3
example.execution_result
end
end
end
end
end
8 changes: 7 additions & 1 deletion lib/turnip_formatter/scenario/pending.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ def validation
private

def pending_message
example.execution_result[:pending_message]
if example.execution_result.is_a?(Hash)
# RSpec 2
example.execution_result[:pending_message]
else
# RSpec 3
example.execution_result.pending_message
end
end
end
end
Expand Down
9 changes: 8 additions & 1 deletion lib/turnip_formatter/step_template/exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ def build_failed(example)
# @param [RSpec::Core::Example] example
#
def build_pending(example)
message = example.execution_result[:pending_message]
if example.execution_result.is_a?(Hash)
# RSpec 2
message = example.execution_result[:pending_message]
else
# RSpec 3
message = example.execution_result.pending_message
end

build(message, [example.location])
end

Expand Down
13 changes: 9 additions & 4 deletions spec/support/example_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ def failed_example

def pending_example
if ::RSpec::Version::STRING >= '2.99.0'
example = base_example { skip('Pending') }
base_example { skip('No such step(0): ') }
else
example = base_example { pending('Pending') }
base_example { pending('No such step(0): ') }
end
end

example.execution_result[:pending_message] = 'No such step(0): '
example
def invalid_pending_example
if ::RSpec::Version::STRING >= '2.99.0'
base_example { skip('Pending') }
else
base_example { pending('Pending') }
end
end

private
Expand Down
2 changes: 1 addition & 1 deletion spec/turnip_formatter/scenario/pending_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

context 'called by not turnip example' do
let(:example) do
pending_example.tap { |e| e.execution_result[:pending_message] = '' }
invalid_pending_example
end

it { should be false }
Expand Down

0 comments on commit ed01197

Please sign in to comment.