Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit e7bb363

Browse files
committed
only use default_path when run with rspec
1 parent f995279 commit e7bb363

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

features/command_line/ruby.feature

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Feature: run with ruby command
22

3-
@wip
3+
You can use the `ruby` command to run specs. You just need to require
4+
`rspec/autorun`.
5+
6+
Generally speaking, you're better off using the `rspec` command, which
7+
requires `rspec/autorun` for you, but some tools only work with the `ruby`
8+
command.
9+
410
Scenario:
511
Given a file named "example_spec.rb" with:
612
"""

lib/rspec/core/configuration.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,14 @@ def reporter
311311

312312
def files_or_directories_to_run=(*files)
313313
files = files.flatten
314-
files << default_path if files.empty? && default_path
314+
files << default_path if command == 'rspec' && default_path && files.empty?
315315
self.files_to_run = get_files_to_run(files)
316316
end
317317

318+
def command
319+
$0.split(File::SEPARATOR).last
320+
end
321+
318322
def get_files_to_run(files)
319323
patterns = pattern.split(",")
320324
files.map do |file|

spec/rspec/core/configuration_spec.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,17 @@ module RSpec::Core
176176
end
177177

178178
context "with default default_path" do
179-
it "loads files named _spec.rb" do
179+
it "loads files in the default path when run by rspec" do
180+
config.stub(:command) { 'rspec' }
180181
config.files_or_directories_to_run = []
181182
config.files_to_run.should_not be_empty
182183
end
184+
185+
it "does not load files in the default path when run by ruby" do
186+
config.stub(:command) { 'ruby' }
187+
config.files_or_directories_to_run = []
188+
config.files_to_run.should be_empty
189+
end
183190
end
184191
end
185192

0 commit comments

Comments
 (0)