Skip to content

Commit

Permalink
Make :example and :context scopes primary.
Browse files Browse the repository at this point in the history
Fixes #1184.
  • Loading branch information
myronmarston committed Mar 21, 2014
1 parent e1d2c40 commit 98a508f
Show file tree
Hide file tree
Showing 20 changed files with 440 additions and 424 deletions.
8 changes: 4 additions & 4 deletions features/command_line/dry_run.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ Feature: --dry-run
end
describe "dry run" do
before(:all) { fail }
before(:each) { fail }
before(:context) { fail }
before(:example) { fail }
it "fails in example" do
fail
end
after(:each) { fail }
after(:all) { fail }
after(:example) { fail }
after(:context) { fail }
end
"""
When I run `rspec --dry-run`
Expand Down
2 changes: 1 addition & 1 deletion features/command_line/order.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Feature: --order (new in rspec-core-2.8)
Use `rand` to randomize the order of groups and examples within groups.*

* Nested groups are always run from top-level to bottom-level in order to avoid
executing `before(:all)` and `after(:all)` hooks more than once, but the order
executing `before(:context)` and `after(:all)` hooks more than once, but the order
of groups at each level is randomized.

You can also specify a seed:
Expand Down
6 changes: 3 additions & 3 deletions features/configuration/overriding_global_ordering.feature
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Feature: Overriding global ordering
Given a file named "order_dependent_spec.rb" with:
"""ruby
describe "examples only pass when they are run in order", :order => :defined do
before(:all) { @list = [] }
before(:context) { @list = [] }
it "passes when run first" do
@list << 1
Expand Down Expand Up @@ -49,7 +49,7 @@ Feature: Overriding global ordering
end
describe "A group that must run in reverse order", :order => :reverse do
before(:all) { @list = [] }
before(:context) { @list = [] }
it "passes when run second" do
@list << 2
Expand All @@ -75,7 +75,7 @@ Feature: Overriding global ordering
end
describe "A group without :order metadata" do
before(:all) { @list = [] }
before(:context) { @list = [] }
it "passes when run second" do
@list << 2
Expand Down
26 changes: 13 additions & 13 deletions features/filtering/exclusion_filters.feature
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Feature: exclusion filters
end
describe "group 1", :broken => true do
before(:all) do
before(:context) do
raise "you should not see me"
end
Expand All @@ -70,7 +70,7 @@ Feature: exclusion filters
end
describe "group 2", :broken => true do
before(:each) do
before(:example) do
raise "you should not see me"
end
Expand All @@ -83,36 +83,36 @@ Feature: exclusion filters
And the output should not contain "group 1"
And the output should not contain "group 2"

Scenario: before/after(:all) hooks in excluded example group are not run
Given a file named "spec/before_after_all_exclusion_filter_spec.rb" with:
Scenario: before/after(:context) hooks in excluded example group are not run
Given a file named "spec/before_after_context_exclusion_filter_spec.rb" with:
"""ruby
RSpec.configure do |c|
c.filter_run_excluding :broken => true
end
describe "group 1" do
before(:all) { puts "before all in included group" }
after(:all) { puts "after all in included group" }
before(:context) { puts "before context in included group" }
after(:context) { puts "after context in included group" }
it "group 1 example" do
end
end
describe "group 2", :broken => true do
before(:all) { puts "before all in excluded group" }
after(:all) { puts "after all in excluded group" }
before(:context) { puts "before context in excluded group" }
after(:context) { puts "after context in excluded group" }
context "context 1" do
it "group 2 context 1 example 1" do
end
end
end
"""
When I run `rspec ./spec/before_after_all_exclusion_filter_spec.rb`
Then the output should contain "before all in included group"
And the output should contain "after all in included group"
And the output should not contain "before all in excluded group"
And the output should not contain "after all in excluded group"
When I run `rspec ./spec/before_after_context_exclusion_filter_spec.rb`
Then the output should contain "before context in included group"
And the output should contain "after context in included group"
And the output should not contain "before context in excluded group"
And the output should not contain "after context in excluded group"

Scenario: Use symbols as metadata
Given a file named "symbols_as_metadata_spec.rb" with:
Expand Down
10 changes: 5 additions & 5 deletions features/filtering/inclusion_filters.feature
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,22 @@ Feature: inclusion filters
And the output should contain "group 1 example 2"
And the output should not contain "group 2 example 1"

Scenario: before/after(:all) hooks in unmatched example group are not run
Scenario: before/after(:context) hooks in unmatched example group are not run
Given a file named "spec/before_after_all_inclusion_filter_spec.rb" with:
"""ruby
require "spec_helper"
describe "group 1", :focus => true do
before(:all) { puts "before all in focused group" }
after(:all) { puts "after all in focused group" }
before(:context) { puts "before all in focused group" }
after(:context) { puts "after all in focused group" }
it "group 1 example" do
end
end
describe "group 2" do
before(:all) { puts "before all in unfocused group" }
after(:all) { puts "after all in unfocused group" }
before(:context) { puts "before all in unfocused group" }
after(:context) { puts "after all in unfocused group" }
context "context 1" do
it "group 2 context 1 example 1" do
Expand Down
94 changes: 47 additions & 47 deletions features/hooks/around_hooks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Feature: around hooks
end
describe "around filter" do
around(:each) do |example|
around(:example) do |example|
Database.transaction(&example)
end
Expand All @@ -49,10 +49,10 @@ Feature: around hooks
Given a file named "example_spec.rb" with:
"""ruby
describe "around hook" do
around(:each) do |example|
puts "around each before"
around(:example) do |example|
puts "around example before"
example.run
puts "around each after"
puts "around example after"
end
it "gets run in order" do
Expand All @@ -63,16 +63,16 @@ Feature: around hooks
When I run `rspec example_spec.rb`
Then the output should contain:
"""
around each before
around example before
in the example
around each after
around example after
"""

Scenario: access the example metadata
Given a file named "example_spec.rb" with:
"""ruby
describe "something" do
around(:each) do |example|
around(:example) do |example|
puts example.metadata[:foo]
example.run
end
Expand All @@ -88,10 +88,10 @@ Feature: around hooks
Given a file named "example_spec.rb" with:
"""ruby
RSpec.configure do |c|
c.around(:each) do |example|
puts "around each before"
c.around(:example) do |example|
puts "around example before"
example.run
puts "around each after"
puts "around example after"
end
end
Expand All @@ -104,27 +104,27 @@ Feature: around hooks
When I run `rspec example_spec.rb`
Then the output should contain:
"""
around each before
around example before
in the example
around each after
around example after
"""

Scenario: before/after(:each) hooks are wrapped by the around hook
Scenario: before/after(:example) hooks are wrapped by the around hook
Given a file named "example_spec.rb" with:
"""ruby
describe "around filter" do
around(:each) do |example|
puts "around each before"
around(:example) do |example|
puts "around example before"
example.run
puts "around each after"
puts "around example after"
end
before(:each) do
puts "before each"
before(:example) do
puts "before example"
end
after(:each) do
puts "after each"
after(:example) do
puts "after example"
end
it "gets run in order" do
Expand All @@ -135,29 +135,29 @@ Feature: around hooks
When I run `rspec example_spec.rb`
Then the output should contain:
"""
around each before
before each
around example before
before example
in the example
after each
around each after
after example
around example after
"""

Scenario: before/after(:all) hooks are NOT wrapped by the around hook
Scenario: before/after(:context) hooks are NOT wrapped by the around hook
Given a file named "example_spec.rb" with:
"""ruby
describe "around filter" do
around(:each) do |example|
puts "around each before"
around(:example) do |example|
puts "around example before"
example.run
puts "around each after"
puts "around example after"
end
before(:all) do
puts "before all"
before(:context) do
puts "before context"
end
after(:all) do
puts "after all"
after(:context) do
puts "after context"
end
it "gets run in order" do
Expand All @@ -168,11 +168,11 @@ Feature: around hooks
When I run `rspec --format progress example_spec.rb`
Then the output should contain:
"""
before all
around each before
before context
around example before
in the example
around each after
.after all
around example after
.after context
"""

Scenario: examples run by an around block are run in the configured context
Expand All @@ -187,7 +187,7 @@ Feature: around hooks
end
describe "around filter" do
around(:each) do |example|
around(:example) do |example|
example.run
end
Expand All @@ -203,7 +203,7 @@ Feature: around hooks
Given a file named "example_spec.rb" with:
"""ruby
describe "implicit pending example" do
around(:each) do |example|
around(:example) do |example|
example.run
end
Expand All @@ -224,7 +224,7 @@ Feature: around hooks
Given a file named "example_spec.rb" with:
"""ruby
describe "explicit pending example" do
around(:each) do |example|
around(:example) do |example|
example.run
end
Expand All @@ -246,13 +246,13 @@ Feature: around hooks
Given a file named "example_spec.rb" with:
"""ruby
describe "if there are multiple around hooks in the same scope" do
around(:each) do |example|
around(:example) do |example|
puts "first around hook before"
example.run
puts "first around hook after"
end
around(:each) do |example|
around(:example) do |example|
puts "second around hook before"
example.run
puts "second around hook after"
Expand All @@ -279,39 +279,39 @@ Feature: around hooks
Given a file named "example_spec.rb" with:
"""ruby
describe "if there are around hooks in an outer scope" do
around(:each) do |example|
around(:example) do |example|
puts "first outermost around hook before"
example.run
puts "first outermost around hook after"
end
around(:each) do |example|
around(:example) do |example|
puts "second outermost around hook before"
example.run
puts "second outermost around hook after"
end
describe "outer scope" do
around(:each) do |example|
around(:example) do |example|
puts "first outer around hook before"
example.run
puts "first outer around hook after"
end
around(:each) do |example|
around(:example) do |example|
puts "second outer around hook before"
example.run
puts "second outer around hook after"
end
describe "inner scope" do
around(:each) do |example|
around(:example) do |example|
puts "first inner around hook before"
example.run
puts "first inner around hook after"
end
around(:each) do |example|
around(:example) do |example|
puts "second inner around hook before"
example.run
puts "second inner around hook after"
Expand Down
Loading

0 comments on commit 98a508f

Please sign in to comment.