Skip to content

Commit

Permalink
Add specs for the consistent ordering of the files to run.
Browse files Browse the repository at this point in the history
These are for #660.
  • Loading branch information
myronmarston committed Sep 8, 2012
1 parent c76c1e6 commit 279a6d6
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
34 changes: 34 additions & 0 deletions spec/rspec/core/configuration_spec.rb
Expand Up @@ -316,6 +316,40 @@ module RSpec::Core
config.files_to_run.should be_empty
end
end

def test_files_to_run_ordering
File.stub(:directory?).with('a') { true }

orderings = [
%w[ a/1.rb a/2.rb a/3.rb ],
%w[ a/2.rb a/1.rb a/3.rb ],
%w[ a/3.rb a/2.rb a/1.rb ]
].map do |files|
Dir.should_receive(:[]).with(/^a/) { files }
yield
config.files_to_run
end.uniq

orderings.size.should eq(1)

This comment has been minimized.

Copy link
@dchelimsky

dchelimsky Sep 9, 2012

Contributor

This is very subtle and subjective, but I think moving uniq to this line would be clearer: orderings.uniq.size.should eq(1)

This comment has been minimized.

Copy link
@myronmarston

myronmarston Sep 10, 2012

Author Member

I think you're right -- the variable should have been called unique_orderings if it was already going to be uniq-ified. It's much clearer seeing one line that specifies that there should be only 1 unique ordering.

end

context 'when the given directories match the pattern' do
it 'orders the files in a consistent ordering, regardless of the underlying OS ordering' do
test_files_to_run_ordering do
config.pattern = 'a/*.rb'
config.files_or_directories_to_run = 'a'
end
end
end

context 'when the pattern is given relative to the given directories' do
it 'orders the files in a consistent ordering, regardless of the underlying OS ordering' do
test_files_to_run_ordering do
config.pattern = '*.rb'
config.files_or_directories_to_run = 'a'
end
end
end
end

%w[pattern= filename_pattern=].each do |setter|
Expand Down
27 changes: 27 additions & 0 deletions spec/rspec/core/rake_task_spec.rb
Expand Up @@ -80,12 +80,39 @@ def spec_command
end
end

def test_files_to_run_ordering(pattern, task)

This comment has been minimized.

Copy link
@dchelimsky

dchelimsky Sep 8, 2012

Contributor

for consistency with the rest of the suite, this should be named spec_files_...

This comment has been minimized.

Copy link
@myronmarston

myronmarston Sep 8, 2012

Author Member

How so? This is testing what files_to_run returns so calling this test_files_to_run_ordering seems more consistent than test_spec_files_to_run_ordering.

Or am I misunderstanding what you're saying?

This comment has been minimized.

Copy link
@dchelimsky

dchelimsky Sep 8, 2012

Contributor

The files are "spec files", not "test files", so it should be spec_files_to_run_ordering. Make sense?

This comment has been minimized.

Copy link
@myronmarston

myronmarston Sep 8, 2012

Author Member

Gotcha, I intended test to be a verb when I wrote this, as in "test the ordering of files_to_run". spec_files_to_run_ordering doesn't quite give the right sense of the method to me--it reads like it will return the ordering of the spec files, when it has no meaningful return value and is simply meant to contain the main logic of the example.

How about something like files_to_run_ordering_should_be_consistent?

This comment has been minimized.

Copy link
@dchelimsky

dchelimsky Sep 9, 2012

Contributor

Even then, "spec" is short of "specify", so "spec[ify] consistent ordering of files" or some such would be more consistent with rspec's intent IMO. Make sense?

This comment has been minimized.

Copy link
@myronmarston

myronmarston Sep 10, 2012

Author Member

I just pushed ced0638 that makes your suggested changes. Thanks for the feedback!

orderings = [
%w[ a/1.rb a/2.rb a/3.rb ],
%w[ a/2.rb a/1.rb a/3.rb ],
%w[ a/3.rb a/2.rb a/1.rb ]
].map do |files|
FileList.should_receive(:[]).with(pattern) { files }
task.__send__(:files_to_run)
end.uniq

orderings.size.should eq(1)
end

context "with SPEC env var set" do
it "sets files to run" do
with_env_vars 'SPEC' => 'path/to/file' do
task.__send__(:files_to_run).should eq(["path/to/file"])
end
end

it "sets the files to run in a consistent order, regardless of the underlying FileList ordering" do
with_env_vars 'SPEC' => 'a/*.rb' do
test_files_to_run_ordering('a/*.rb', task)
end
end
end

it "sets the files to run in a consistent order, regardless of the underlying FileList ordering" do
task = RakeTask.new do |t|
t.pattern = 'a/*.rb'
end

test_files_to_run_ordering('a/*.rb', task)
end

context "with paths with quotes" do
Expand Down

0 comments on commit 279a6d6

Please sign in to comment.