Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Mixing nested groups and outer-level examples gives unpredictable :line_number behavior #340

Closed
wants to merge 1 commit into from

2 participants

@arturmalecki

In case were 'it' is after 'describe' in code, rspec invoke 'it' before 'describe'.

Artur Małecki Fixed! 0107fae
@arturmalecki

Fix bug where mixing nested groups and outer-level examples gave
unpredictable :line_number behavior

@dchelimsky dchelimsky closed this
@andreastt andreastt referenced this pull request from a commit
Artur Małecki Fix bug where mixing nested groups and outer-level examples gave
unpredictable :line_number behavior

- Closes #337.
- Closes #340.
a368a1a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 23, 2011
  1. Fixed!

    Artur Małecki authored
This page is out of date. Refresh to see the latest.
Showing with 39 additions and 16 deletions.
  1. +1 −1  lib/rspec/core/world.rb
  2. +38 −15 spec/rspec/core/world_spec.rb
View
2  lib/rspec/core/world.rb
@@ -54,7 +54,7 @@ def apply_exclusion_filters(examples, conditions={})
end
def preceding_declaration_line(filter_line)
- declaration_line_numbers.inject(nil) do |highest_prior_declaration_line, line|
+ declaration_line_numbers.sort.inject(nil) do |highest_prior_declaration_line, line|
line <= filter_line ? line : highest_prior_declaration_line
end
end
View
53 spec/rspec/core/world_spec.rb
@@ -138,7 +138,15 @@ module RSpec::Core
let(:group) do
RSpec::Core::ExampleGroup.describe("group") do
- example("example") {}
+ example("example") {}
+
+ end
+ end
+
+ let(:second_group) do
+ RSpec::Core::ExampleGroup.describe("second_group") do
+
+ example("second_example") {}
end
end
@@ -146,26 +154,41 @@ module RSpec::Core
let(:group_declaration_line) { group.metadata[:example_group][:line_number] }
let(:example_declaration_line) { group_declaration_line + 2 }
- before { world.register(group) }
+ context "with one example" do
+ before { world.register(group) }
- it "returns nil if no example or group precedes the line" do
- world.preceding_declaration_line(group_declaration_line - 1).should be_nil
- end
+ it "returns nil if no example or group precedes the line" do
+ world.preceding_declaration_line(group_declaration_line - 1).should be_nil
+ end
- it "returns the argument line number if a group starts on that line" do
- world.preceding_declaration_line(group_declaration_line).should eq(group_declaration_line)
- end
+ it "returns the argument line number if a group starts on that line" do
+ world.preceding_declaration_line(group_declaration_line).should eq(group_declaration_line)
+ end
- it "returns the argument line number if an example starts on that line" do
- world.preceding_declaration_line(example_declaration_line).should eq(example_declaration_line)
- end
+ it "returns the argument line number if an example starts on that line" do
+ world.preceding_declaration_line(example_declaration_line).should eq(example_declaration_line)
+ end
- it "returns line number of a group that immediately precedes the argument line" do
- world.preceding_declaration_line(group_declaration_line + 1).should eq(group_declaration_line)
+ it "returns line number of a group that immediately precedes the argument line" do
+ world.preceding_declaration_line(group_declaration_line + 1).should eq(group_declaration_line)
+ end
+
+ it "returns line number of an example that immediately precedes the argument line" do
+ world.preceding_declaration_line(example_declaration_line + 1).should eq(example_declaration_line)
+ end
end
- it "returns line number of an example that immediately precedes the argument line" do
- world.preceding_declaration_line(example_declaration_line + 1).should eq(example_declaration_line)
+ context "with two exaples and the second example is registre first" do
+ let(:second_group_declaration_line) { second_group.metadata[:example_group][:line_number] }
+
+ before do
+ world.register(second_group)
+ world.register(group)
+ end
+
+ it 'return line number of group if a group start on that line' do
+ world.preceding_declaration_line(second_group_declaration_line).should eq(second_group_declaration_line)
+ end
end
end
Something went wrong with that request. Please try again.