Skip to content

Commit

Permalink
Cleaned specs.
Browse files Browse the repository at this point in the history
Signed-off-by: Rémy Coutable <rymai@rymai.me>
  • Loading branch information
Rémy Coutable committed Apr 17, 2011
1 parent f241899 commit c94e635
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 50 deletions.
2 changes: 1 addition & 1 deletion Guardfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
guard 'rspec', :cli => "-c -r rspec/instafail -f RSpec::Instafail" do
guard 'rspec', :cli => "-c -f doc" do
watch(%r{^spec/.+_spec\.rb})
watch(%r{^lib/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace :spec do

desc "Run all specs on multiple ruby versions (requires rvm and bundler)"
task :portability do
%w[1.8.6 1.8.7 ree 1.9.2 jruby rubinius].each do |version|
%w[1.8.6 1.8.7 ree 1.9.2 rbx jruby].each do |version|
system <<-BASH
bash -c 'source ~/.rvm/scripts/rvm;
rvm #{version};
Expand Down
1 change: 0 additions & 1 deletion guard-rspec.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Gem::Specification.new do |s|

s.add_development_dependency 'bundler', '~> 1.0'
s.add_development_dependency 'rspec', '~> 2.5'
s.add_development_dependency 'rspec-instafail'

s.files = Dir.glob('{lib}/**/*') + %w[LICENSE README.rdoc]
s.require_path = 'lib'
Expand Down
18 changes: 8 additions & 10 deletions spec/guard/rspec/inspector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,37 @@
describe Guard::RSpec::Inspector do

describe ".clean" do

it "should remove non-spec files" do
it "removes non-spec files" do
subject.clean(["spec/guard/rspec_spec.rb", "bob.rb"]).should == ["spec/guard/rspec_spec.rb"]
end

it "should remove spec-looking but non-existing files" do
it "removes spec-looking but non-existing files" do
subject.clean(["spec/guard/rspec_spec.rb", "bob_spec.rb"]).should == ["spec/guard/rspec_spec.rb"]
end

it "should remove spec-looking but non-existing files (2)" do
it "removes spec-looking but non-existing files (2)" do
subject.clean(["spec/guard/rspec/formatter_spec.rb"]).should == []
end

it "should keep spec folder path" do
it "keeps spec folder path" do
subject.clean(["spec/guard/rspec_spec.rb", "spec/models"]).should == ["spec/guard/rspec_spec.rb", "spec/models"]
end

it "should remove duplication" do
it "removes duplication" do
subject.clean(["spec", "spec"]).should == ["spec"]
end

it "should remove spec folders included in other spec folders" do
it "removes spec folders included in other spec folders" do
subject.clean(["spec/models", "spec"]).should == ["spec"]
end

it "should remove spec files included in spec folders" do
it "removes spec files included in spec folders" do
subject.clean(["spec/guard/rspec_spec.rb", "spec"]).should == ["spec"]
end

it "should remove spec files included in spec folders (2)" do
it "removes spec files included in spec folders (2)" do
subject.clean(["spec/guard/rspec_spec.rb", "spec/guard/rspec/runner_spec.rb", "spec/guard/rspec"]).should == ["spec/guard/rspec_spec.rb", "spec/guard/rspec"]
end

end

end
37 changes: 17 additions & 20 deletions spec/guard/rspec/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
describe Guard::RSpec::Runner do

describe ".run" do

context "when passed an empty paths list" do
it "should return false" do
it "returns false" do
subject.run([]).should be_false
end
end
Expand All @@ -16,7 +15,7 @@
subject.set_rspec_version
end

it "should run with RSpec 2 and without bundler" do
it "runs with RSpec 2 and without bundler" do
subject.should_receive(:system).with(
"rspec -f progress -r #{@lib_path.join('guard/rspec/formatters/notification_rspec.rb')} -f NotificationRSpec --out /dev/null spec"
)
Expand All @@ -30,7 +29,7 @@
subject.set_rspec_version
end

it "should run with RSpec 2 and with Bundler" do
it "runs with RSpec 2 and with Bundler" do
subject.should_receive(:system).with(
"bundle exec rspec -f progress -r #{@lib_path.join('guard/rspec/formatters/notification_rspec.rb')} -f NotificationRSpec --out /dev/null spec"
)
Expand All @@ -39,7 +38,7 @@

describe "options" do
describe ":rvm" do
it "should run with rvm exec" do
it "runs with rvm exec" do
subject.should_receive(:system).with(
"rvm 1.8.7,1.9.2 exec bundle exec rspec -f progress -r #{@lib_path.join('guard/rspec/formatters/notification_rspec.rb')} -f NotificationRSpec --out /dev/null spec"
)
Expand All @@ -48,21 +47,21 @@
end

describe ":cli" do
it "should run with CLI options passed to RSpec" do
it "runs with CLI options passed to RSpec" do
subject.should_receive(:system).with(
"bundle exec rspec --color --drb --fail-fast -f progress -r #{@lib_path.join('guard/rspec/formatters/notification_rspec.rb')} -f NotificationRSpec --out /dev/null spec"
)
subject.run(["spec"], :cli => "--color --drb --fail-fast")
end

it "should set progress formatter by default if no formatter is passed in CLI options to RSpec" do
it "sets progress formatter by default if no formatter is passed in CLI options to RSpec" do
subject.should_receive(:system).with(
"bundle exec rspec -f progress -r #{@lib_path.join('guard/rspec/formatters/notification_rspec.rb')} -f NotificationRSpec --out /dev/null spec"
)
subject.run(["spec"])
end

it "should respect formatter passed in CLI options to RSpec" do
it "respects formatter passed in CLI options to RSpec" do
subject.should_receive(:system).with(
"bundle exec rspec -f doc -r #{@lib_path.join('guard/rspec/formatters/notification_rspec.rb')} -f NotificationRSpec --out /dev/null spec"
)
Expand All @@ -71,7 +70,7 @@
end

describe ":bundler" do
it "should run without Bundler with bundler option to false" do
it "runs without Bundler with bundler option to false" do
subject.should_receive(:system).with(
"rspec -f progress -r #{@lib_path.join('guard/rspec/formatters/notification_rspec.rb')} -f NotificationRSpec --out /dev/null spec"
)
Expand All @@ -80,7 +79,7 @@
end

describe ":notification" do
it "should run without notification formatter with notification option to false" do
it "runs without notification formatter with notification option to false" do
subject.should_receive(:system).with(
"bundle exec rspec -f progress spec"
)
Expand All @@ -91,7 +90,7 @@
describe "deprecated options" do
[:color, :drb, :fail_fast, [:formatter, "format"]].each do |option|
key, value = option.is_a?(Array) ? option : [option, option.to_s]
it "should output deprecation warning for :#{key} option" do
it "outputs deprecation warning for :#{key} option" do
Guard::UI.should_receive(:info).with("Running: spec", { :reset => true }).ordered
Guard::UI.should_receive(:info).with(%{DEPRECATION WARNING: The :#{key} option is deprecated. Pass standard command line argument "--#{value.gsub('_', '-')}" to RSpec with the :cli option.}).ordered
subject.stub(:system)
Expand All @@ -108,27 +107,25 @@
subject.set_rspec_version
end

it "should run with RSpec 1 and with bundler" do
it "runs with RSpec 1 and with bundler" do
subject.should_receive(:system).with(
"bundle exec spec -f progress -r #{@lib_path.join('guard/rspec/formatters/notification_spec.rb')} -f NotificationSpec:/dev/null spec"
)
subject.run(["spec"])
end
end

end

describe ".set_rspec_version" do

it "should use version option first" do
it "uses version option first" do
subject.set_rspec_version(:version => 1)
subject.rspec_version.should == 1
end

context "in empty folder" do
before(:each) { Dir.stub(:pwd).and_return(@fixture_path.join("empty")) }

it "should set RSpec 2 because cannot determine version" do
it "sets RSpec 2 because cannot determine version" do
subject.set_rspec_version
subject.rspec_version.should == 2
end
Expand All @@ -137,7 +134,7 @@
context "in RSpec 1 folder with Bundler" do
before(:each) { Dir.stub(:pwd).and_return(@fixture_path.join("bundler_only_rspec1")) }

it "should set RSpec 1 from Bundler" do
it "sets RSpec 1 from Bundler" do
subject.set_rspec_version
subject.rspec_version.should == 1
end
Expand All @@ -146,7 +143,7 @@
context "in RSpec 2 folder with Bundler" do
before(:each) { Dir.stub(:pwd).and_return(@fixture_path.join("bundler_only_rspec2")) }

it "should set RSpec 2 from Bundler" do
it "sets RSpec 2 from Bundler" do
subject.set_rspec_version
subject.rspec_version.should == 2
end
Expand All @@ -155,7 +152,7 @@
context "in RSpec 1 folder without Bundler" do
before(:each) { Dir.stub(:pwd).and_return(@fixture_path.join("rspec1")) }

it "should set RSpec 1 from spec_helper.rb" do
it "sets RSpec 1 from spec_helper.rb" do
subject.set_rspec_version
subject.rspec_version.should == 1
end
Expand All @@ -164,7 +161,7 @@
context "in RSpec 2 folder without Bundler" do
before(:each) { Dir.stub(:pwd).and_return(@fixture_path.join("rspec2")) }

it "should set RSpec 2 from spec_helper.rb" do
it "sets RSpec 2 from spec_helper.rb" do
subject.set_rspec_version
subject.rspec_version.should == 2
end
Expand Down
34 changes: 17 additions & 17 deletions spec/guard/rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,70 @@
subject { Guard::RSpec.new }

describe '#initialize' do
it 'should set rspec_version' do
it 'sets rspec_version' do
Guard::RSpec::Runner.should_receive(:set_rspec_version)
Guard::RSpec.new
end
end

describe "start" do
it "should run_all" do
describe "#start" do
it "calls #run_all" do
Guard::RSpec::Runner.should_receive(:run).with(["spec"], :message => "Running all specs")
subject.start
end

it "should not run_all if all_on_start is false" do
it "doesn't call #run_all if the :all_on_start option is false" do
Guard::RSpec::Runner.should_not_receive(:run).with(["spec"], :message => "Running all specs")
subject = Guard::RSpec.new([], :all_on_start => false)
subject.start
end
end

describe "run_all" do
it "should run all spec" do
describe "#run_all" do
it "runs all specs" do
Guard::RSpec::Runner.should_receive(:run).with(["spec"], :message => "Running all specs")
subject.run_all
end
it "should pass options to runner" do

it "directly passes :cli option to runner" do
subject = Guard::RSpec.new([], { :cli => "--color" })
Guard::RSpec::Runner.should_receive(:run).with(["spec"], :message => "Running all specs", :cli => "--color")
subject.run_all
end
end
describe "run_on_change" do
it "should run rspec with paths" do

describe "#run_on_change" do
it "runs rspec with paths" do
Guard::RSpec::Runner.should_receive(:run).with(["spec"], {})
subject.run_on_change(["spec"])
end
it "should pass options to runner" do

it "directly passes :cli option to runner" do
subject = Guard::RSpec.new([], { :cli => "--color" })
Guard::RSpec::Runner.should_receive(:run).with(["spec"], :cli => "--color")
subject.run_on_change(["spec"])
end

it "should run_all if the changed specs pass after failing" do
it "calls #run_all if the changed specs pass after failing" do
Guard::RSpec::Runner.should_receive(:run).with(["spec/foo"], {}).and_return(false, true)
Guard::RSpec::Runner.should_receive(:run).with(["spec"], :message => "Running all specs")
subject.run_on_change(["spec/foo"])
subject.run_on_change(["spec/foo"])
end

it "should not run_all if if the changed specs pass after failing but all_after_pass is false" do
it "doesn't call #run_all if the changed specs pass after failing but the :all_after_pass option is false" do
subject = Guard::RSpec.new([], :all_after_pass => false)
Guard::RSpec::Runner.should_receive(:run).with(["spec/foo"], {}).and_return(false, true)
Guard::RSpec::Runner.should_not_receive(:run).with(["spec"], :message => "Running all specs")
subject.run_on_change(["spec/foo"])
subject.run_on_change(["spec/foo"])
end

it "should not run_all if the changed specs pass without failing" do
it "doesn't call #run_all if the changed specs pass without failing" do
Guard::RSpec::Runner.should_receive(:run).with(["spec/foo"], {}).and_return(true)
Guard::RSpec::Runner.should_not_receive(:run).with(["spec"], :message => "Running all specs")
subject.run_on_change(["spec/foo"])
end
end

end

0 comments on commit c94e635

Please sign in to comment.