Skip to content

Commit

Permalink
Add additional statuses to Sandbox::Result.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepingkingstudios committed Jul 31, 2024
1 parent c6896ba commit 5df3d28
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
24 changes: 24 additions & 0 deletions lib/rspec/sleeping_king_studios/sandbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,30 @@ def example_descriptions
json['examples'].map { |hsh| hsh['full_description'] }
end

# @return [Array<String>] the full description for each run example with
# status "failed".
def failing_examples
json['examples']
.select { |hsh| hsh['status'] == 'failed' }
.map { |hsh| hsh['full_description'] }
end

# @return [Array<String>] the full description for each run example with
# status "passed".
def passing_examples
json['examples']
.select { |hsh| hsh['status'] == 'passed' }
.map { |hsh| hsh['full_description'] }
end

# @return [Array<String>] the full description for each run example with
# status "pending".
def pending_examples
json['examples']
.select { |hsh| hsh['status'] == 'pending' }
.map { |hsh| hsh['full_description'] }
end

# @return [String] the summary of the sandboxed spec run.
def summary
json['summary_line']
Expand Down
45 changes: 44 additions & 1 deletion spec/rspec/sleeping_king_studios/sandbox/result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#launch
should launch the rocket
should set the launch site
should not explode
OUTPUT
end
let(:errors) { '' }
Expand All @@ -31,12 +32,18 @@
'examples' => [
{
'full_description' => 'Spec::Models::Rocket#launch should launch the rocket',
'status' => 'passed'
},
{
'full_description' => 'Spec::Models::Rocket#launch should set the launch site',
'status' => 'failed'
},
{
'full_description' => 'Spec::Models::Rocket#launch should not explode',
'status' => 'pending'
}
],
'summary_line' => '2 examples, 0 failures'
'summary_line' => '3 examples, 0 failures'
}
# rubocop:enable RSpec/LineLength
end
Expand All @@ -55,6 +62,18 @@
-> { expected }
end

describe '#failing_examples' do
let(:expected) do
json['examples']
.select { |hsh| hsh['status'] == 'failed' }
.map { |hsh| hsh['full_description'] }
end

include_examples 'should define reader',
:failing_examples,
-> { expected }
end

describe '#json' do
include_examples 'should define reader', :json, -> { json }
end
Expand All @@ -63,6 +82,30 @@
include_examples 'should define reader', :output, -> { output }
end

describe '#passing_examples' do
let(:expected) do
json['examples']
.select { |hsh| hsh['status'] == 'passed' }
.map { |hsh| hsh['full_description'] }
end

include_examples 'should define reader',
:passing_examples,
-> { expected }
end

describe '#pending_examples' do
let(:expected) do
json['examples']
.select { |hsh| hsh['status'] == 'pending' }
.map { |hsh| hsh['full_description'] }
end

include_examples 'should define reader',
:pending_examples,
-> { expected }
end

describe '#status' do
include_examples 'should define reader', :status, -> { status }
end
Expand Down

0 comments on commit 5df3d28

Please sign in to comment.