Browse files

Fix bug where mixing nested groups and outer-level examples gave

unpredictable :line_number behavior

- Closes #337.
- Closes #340.
  • Loading branch information...
1 parent 8fd03d2 commit a368a1ab2b0bfce1cc0ad3bde446038f96207e9f Artur Małecki committed with dchelimsky Mar 23, 2011
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,34 +138,57 @@ 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
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

0 comments on commit a368a1a

Please sign in to comment.