Skip to content
Browse files

Add specs for the consistent ordering of the files to run.

These are for #660.
  • Loading branch information...
1 parent c76c1e6 commit 279a6d6f63d5e55e88e91b7a0f1dae4142bb6c9c @myronmarston myronmarston committed
Showing with 61 additions and 0 deletions.
  1. +34 −0 spec/rspec/core/configuration_spec.rb
  2. +27 −0 spec/rspec/core/rake_task_spec.rb
View
34 spec/rspec/core/configuration_spec.rb
@@ -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)
@dchelimsky RSpec member

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

@myronmarston RSpec 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ 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|
View
27 spec/rspec/core/rake_task_spec.rb
@@ -80,12 +80,39 @@ def spec_command
end
end
+ def test_files_to_run_ordering(pattern, task)
@dchelimsky RSpec member

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

@myronmarston RSpec 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?

@dchelimsky RSpec member

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

@myronmarston RSpec 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?

@dchelimsky RSpec member

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?

@myronmarston RSpec member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ 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

0 comments on commit 279a6d6

Please sign in to comment.
Something went wrong with that request. Please try again.