Skip to content

Commit

Permalink
support line number appended to path
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Jan 26, 2010
1 parent 5f754c6 commit 500ec9a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 57 deletions.
56 changes: 0 additions & 56 deletions features-pending/command_line/line_number_option.feature

This file was deleted.

39 changes: 39 additions & 0 deletions features/command_line/line_number_appended_to_path.feature
@@ -0,0 +1,39 @@
Feature: line number appended to file path

As an RSpec user
I want to run one example identified by the
line number appended to the filepath

Background:
Given a file named "example_spec.rb" with:
"""
describe "a group" do
it "has a first example" do
end
it "has a second example" do
end
end
"""

Scenario: two examples - both examples from the group declaration
When I run "spec example_spec.rb:1 --format doc"
Then the stdout should match "2 examples, 0 failures"
And the stdout should match "has a second example"
And the stdout should match "has a first example"

Scenario: two examples - first example on declaration line
When I run "spec example_spec.rb:3 --format doc"
Then the stdout should match "1 example, 0 failures"
And the stdout should match "has a first example"
But the stdout should not match "has a second example"

Scenario: two examples - second example on declaration line
When I run "spec example_spec.rb:7 --format doc"
Then the stdout should match "1 example, 0 failures"
And the stdout should match "has a second example"
But the stdout should not match "has a first example"
5 changes: 4 additions & 1 deletion lib/rspec/core/configuration.rb
Expand Up @@ -137,13 +137,16 @@ def files_to_run
end end


def files_or_directories_to_run=(*files) def files_or_directories_to_run=(*files)
p files
options[:files_to_run] = files.flatten.inject([]) do |result, file| options[:files_to_run] = files.flatten.inject([]) do |result, file|
if File.directory?(file) if File.directory?(file)
filename_pattern.split(",").each do |pattern| filename_pattern.split(",").each do |pattern|
result += Dir[File.expand_path("#{file}/#{pattern.strip}")] result += Dir[File.expand_path("#{file}/#{pattern.strip}")]
end end
else else
result << file file =~ /([^:]*):?(\d+)?/
self.line_number = $2 if $2
result << $1
end end
result result
end end
Expand Down
9 changes: 9 additions & 0 deletions spec/rspec/core/configuration_spec.rb
Expand Up @@ -102,6 +102,15 @@


end end


context "with line number" do

it "assigns the line number as the filter" do
@config.files_or_directories_to_run = "path/to/a_spec.rb:37"
@config.filter.should == {:line_number => 37}
end

end

end end


describe "include" do describe "include" do
Expand Down

0 comments on commit 500ec9a

Please sign in to comment.