Permalink
Browse files

Support new RSpec expectation syntax and new guard-rspec

  • Loading branch information...
1 parent 8a579e2 commit afa277b95d61e6604b7627c846b595079fab45f4 @rymai rymai committed Oct 27, 2013
View
@@ -1,14 +1,13 @@
group :specs do
- guard :rspec, cli: '--format doc' do
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
+ guard :rspec, cmd: 'bundle exec rspec -f doc' do
+ watch(%r{^(lib/.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^spec/.+_spec\.rb$})
watch('spec/spec_helper.rb') { "spec" }
end
end
group :tests do
guard :test do
- watch(%r{lib/(.+)\.rb}) { |m| "test/#{m[1]}_test.rb" }
watch(%r{test/.+_test\.rb})
watch('test/test_helper.rb') { "test" }
end
@@ -51,7 +51,7 @@ def clear_test_files_list
end
def check_test_files(path)
- Dir[File.join(path, '**', 'test_*.rb')] +
+ Dir[File.join(path, '**', 'test_*.rb')] +
Dir[File.join(path, '**', '*_test{s,}.rb')]
end
end
@@ -7,53 +7,53 @@
before { subject.test_paths = ["test"] }
it "should add all test files under the given dir" do
- subject.clean(["test"]).should \
- == ["test/succeeding_test.rb", "test/succeeding_tests.rb", "test/test_old.rb", "test/unit/error/error_test.rb", "test/unit/failing_test.rb"]
+ expect(subject.clean(["test"])).to \
+ eq ["test/succeeding_test.rb", "test/succeeding_tests.rb", "test/test_old.rb", "test/unit/error/error_test.rb", "test/unit/failing_test.rb"]
end
it "should remove non-test files" do
- subject.clean(["test/succeeding_test.rb", "bob.rb"]).should == ["test/succeeding_test.rb"]
+ expect(subject.clean(["test/succeeding_test.rb", "bob.rb"])).to eq ["test/succeeding_test.rb"]
end
it "should remove non-existing test files" do
- subject.clean(["test/succeeding_test.rb", "bob_test.rb"]).should == ["test/succeeding_test.rb"]
+ expect(subject.clean(["test/succeeding_test.rb", "bob_test.rb"])).to eq ["test/succeeding_test.rb"]
end
it "should remove non-existing test files (2)" do
- subject.clean(["test/bar_test.rb"]).should == []
+ expect(subject.clean(["test/bar_test.rb"])).to eq []
end
it "should keep test folder path" do
- subject.clean(["test/succeeding_test.rb", "test/unit"]).should \
- == ["test/succeeding_test.rb", "test/unit/error/error_test.rb", "test/unit/failing_test.rb"]
+ expect(subject.clean(["test/succeeding_test.rb", "test/unit"])).to \
+ eq ["test/succeeding_test.rb", "test/unit/error/error_test.rb", "test/unit/failing_test.rb"]
end
it "should remove duplication" do
- subject.clean(["test", "test"]).should \
- == ["test/succeeding_test.rb", "test/succeeding_tests.rb", "test/test_old.rb", "test/unit/error/error_test.rb", "test/unit/failing_test.rb"]
+ expect(subject.clean(["test", "test"])).to \
+ eq ["test/succeeding_test.rb", "test/succeeding_tests.rb", "test/test_old.rb", "test/unit/error/error_test.rb", "test/unit/failing_test.rb"]
end
it "should remove test folder includes in other test folder" do
- subject.clean(["test/unit", "test"]).should \
- == ["test/succeeding_test.rb", "test/succeeding_tests.rb", "test/test_old.rb", "test/unit/error/error_test.rb", "test/unit/failing_test.rb"]
+ expect(subject.clean(["test/unit", "test"])).to \
+ eq ["test/succeeding_test.rb", "test/succeeding_tests.rb", "test/test_old.rb", "test/unit/error/error_test.rb", "test/unit/failing_test.rb"]
end
it "should remove test files includes in test folder" do
- subject.clean(["test/unit/failing_test.rb", "test"]).should \
- == ["test/succeeding_test.rb", "test/succeeding_tests.rb", "test/test_old.rb", "test/unit/error/error_test.rb", "test/unit/failing_test.rb"]
+ expect(subject.clean(["test/unit/failing_test.rb", "test"])).to \
+ eq ["test/succeeding_test.rb", "test/succeeding_tests.rb", "test/test_old.rb", "test/unit/error/error_test.rb", "test/unit/failing_test.rb"]
end
it "should remove test files includes in test folder (2)" do
- subject.clean(["test/unit/failing_test.rb", "test/unit/error/error_test.rb", "test/unit/error"]).should \
- == ["test/unit/error/error_test.rb", "test/unit/failing_test.rb"]
+ expect(subject.clean(["test/unit/failing_test.rb", "test/unit/error/error_test.rb", "test/unit/error"])).to \
+ eq ["test/unit/error/error_test.rb", "test/unit/failing_test.rb"]
end
context "when test_paths is not default" do
before { subject.test_paths = ["test/unit/error"] }
it "should clean paths not specified" do
- subject.clean(['test/succeeding_test.rb', 'test/unit/error/error_test.rb']).should \
- == ['test/unit/error/error_test.rb']
+ expect(subject.clean(['test/succeeding_test.rb', 'test/unit/error/error_test.rb'])).to \
+ eq ['test/unit/error/error_test.rb']
end
end
@@ -9,23 +9,23 @@
context "no failure, no error" do
it "displays a 'success' image" do
result = create_mock_result
- Guard::Notifier.should_receive(:notify).with(anything, title: "Test::Unit results", image: :success)
+ expect(Guard::Notifier).to receive(:notify).with(anything, title: "Test::Unit results", image: :success)
described_class.notify(result, 0)
end
end
context "1 failure" do
it "displays a 'failed' image" do
result = create_mock_result(failure_count: 1)
- Guard::Notifier.should_receive(:notify).with(anything, title: "Test::Unit results", image: :failed)
+ expect(Guard::Notifier).to receive(:notify).with(anything, title: "Test::Unit results", image: :failed)
described_class.notify(result, 0)
end
end
context "1 error" do
it "displays a 'failed' image" do
result = create_mock_result(error_count: 1)
- Guard::Notifier.should_receive(:notify).with(anything, title: "Test::Unit results", image: :failed)
+ expect(Guard::Notifier).to receive(:notify).with(anything, title: "Test::Unit results", image: :failed)
described_class.notify(result, 0)
end
end
@@ -5,7 +5,7 @@
describe "run" do
it "should be in early development stage" do
- described_class::VERSION.should eq '2.0.0'
+ expect(described_class::VERSION).to eq '2.0.0'
end
end
@@ -7,13 +7,13 @@
describe "#initialize" do
it "instantiates a new Runner" do
- Guard::Test::Runner.should_receive(:new)
+ expect(Guard::Test::Runner).to receive(:new)
described_class.new
end
context "with options given" do
it "passes fiven options to Guard::Test::Runner#new" do
- Guard::Test::Runner.should_receive(:new).with(rvm: ['1.8.7', '1.9.2'], bundler: false).and_return(double('runner', bundler?: true))
+ expect(Guard::Test::Runner).to receive(:new).with(rvm: ['1.8.7', '1.9.2'], bundler: false).and_return(double('runner', bundler?: true))
described_class.new(rvm: ['1.8.7', '1.9.2'], bundler: false)
end
@@ -23,14 +23,14 @@
describe "#start" do
context ":all_on_start option not specified" do
it "displays a start message" do
- ::Guard::UI.should_receive(:info).with("Guard::Test #{Guard::TestVersion::VERSION} is running, with Test::Unit #{::Test::Unit::VERSION}!", reset: true)
+ expect(::Guard::UI).to receive(:info).with("Guard::Test #{Guard::TestVersion::VERSION} is running, with Test::Unit #{::Test::Unit::VERSION}!", reset: true)
subject.stub(:run_all)
subject.start
end
it "calls #run_all by default" do
- subject.should_receive(:run_all)
+ expect(subject).to receive(:run_all)
subject.start
end
@@ -40,7 +40,7 @@
subject { described_class.new(all_on_start: false) }
it "doesn't call #run_all" do
- subject.should_not_receive(:run_all)
+ expect(subject).to_not receive(:run_all)
subject.start
end
@@ -50,7 +50,7 @@
describe "#run_all" do
it "runs all tests specified by the default :test_paths with a message" do
- runner.should_receive(:run).with(["test/succeeding_test.rb", "test/succeeding_tests.rb", "test/test_old.rb", "test/unit/error/error_test.rb", "test/unit/failing_test.rb"],message: "Running all tests"
+ expect(runner).to receive(:run).with(["test/succeeding_test.rb", "test/succeeding_tests.rb", "test/test_old.rb", "test/unit/error/error_test.rb", "test/unit/failing_test.rb"],message: "Running all tests"
)
subject.run_all
end
@@ -59,72 +59,72 @@
subject { described_class.new(test_paths: ["test/unit/error"]) }
it "runs all tests in specific directory" do
- runner.should_receive(:run).with(["test/unit/error/error_test.rb"], anything)
+ expect(runner).to receive(:run).with(["test/unit/error/error_test.rb"], anything)
subject.run_all
end
end
it "cleans failed memory if passed" do
- runner.should_receive(:run).with(["test/unit/error/error_test.rb", "test/unit/failing_test.rb"]).and_return(false)
+ expect(runner).to receive(:run).with(["test/unit/error/error_test.rb", "test/unit/failing_test.rb"]).and_return(false)
subject.run_on_changes(["test/unit"])
- runner.should_receive(:run).with(["test/succeeding_test.rb", "test/succeeding_tests.rb", "test/test_old.rb", "test/unit/error/error_test.rb", "test/unit/failing_test.rb"], message: "Running all tests").and_return(true)
+ expect(runner).to receive(:run).with(["test/succeeding_test.rb", "test/succeeding_tests.rb", "test/test_old.rb", "test/unit/error/error_test.rb", "test/unit/failing_test.rb"], message: "Running all tests").and_return(true)
subject.run_all
- runner.should_receive(:run).with(["test/unit/error/error_test.rb", "test/unit/failing_test.rb"]).and_return(true)
+ expect(runner).to receive(:run).with(["test/unit/error/error_test.rb", "test/unit/failing_test.rb"]).and_return(true)
subject.run_on_changes(["test/unit"])
end
it "init test_paths for Inspector" do
- runner.should_receive(:run)
- Guard::Test::Inspector.should_receive(:test_paths=).with(["test"])
+ expect(runner).to receive(:run)
+ expect(Guard::Test::Inspector).to receive(:test_paths=).with(["test"])
subject.run_all
end
end
describe "#reload" do
it "should clear failed_path" do
- runner.should_receive(:run).with(["test/unit/error/error_test.rb", "test/unit/failing_test.rb"]).and_return(false)
+ expect(runner).to receive(:run).with(["test/unit/error/error_test.rb", "test/unit/failing_test.rb"]).and_return(false)
subject.run_on_changes(["test/unit"])
subject.reload
- runner.should_receive(:run).with(["test/unit/error/error_test.rb", "test/unit/failing_test.rb"]).and_return(true)
- runner.should_receive(:run).with(["test/succeeding_test.rb", "test/succeeding_tests.rb", "test/test_old.rb", "test/unit/error/error_test.rb", "test/unit/failing_test.rb"], message: "Running all tests").and_return(true)
+ expect(runner).to receive(:run).with(["test/unit/error/error_test.rb", "test/unit/failing_test.rb"]).and_return(true)
+ expect(runner).to receive(:run).with(["test/succeeding_test.rb", "test/succeeding_tests.rb", "test/test_old.rb", "test/unit/error/error_test.rb", "test/unit/failing_test.rb"], message: "Running all tests").and_return(true)
subject.run_on_changes(["test/unit"])
end
end
describe "#run_on_changes" do
it "runs test after run_all" do
- runner.should_receive(:run)
+ expect(runner).to receive(:run)
subject.run_all
- runner.should_receive(:run).with(["test/unit/error/error_test.rb"])
+ expect(runner).to receive(:run).with(["test/unit/error/error_test.rb"])
subject.run_on_changes(["test/unit/error/error_test.rb"])
end
it "init test_paths for Inspector" do
- Guard::Test::Inspector.should_receive(:test_paths=).with(["test"])
+ expect(Guard::Test::Inspector).to receive(:test_paths=).with(["test"])
subject.run_on_changes([])
end
context ":all_after_pass option not specified" do
it "runs test with under given paths, recursively" do
- runner.should_receive(:run).with(["test/unit/error/error_test.rb", "test/unit/failing_test.rb"])
+ expect(runner).to receive(:run).with(["test/unit/error/error_test.rb", "test/unit/failing_test.rb"])
subject.run_on_changes(["test/unit"])
end
it "calls #run_all by default if the changed specs pass after failing" do
- runner.should_receive(:run).with(["test/succeeding_test.rb"]).and_return(false, true)
- runner.should_receive(:run).with(["test/succeeding_test.rb", "test/succeeding_tests.rb", "test/test_old.rb", "test/unit/error/error_test.rb", "test/unit/failing_test.rb"], message: "Running all tests")
+ expect(runner).to receive(:run).with(["test/succeeding_test.rb"]).and_return(false, true)
+ expect(runner).to receive(:run).with(["test/succeeding_test.rb", "test/succeeding_tests.rb", "test/test_old.rb", "test/unit/error/error_test.rb", "test/unit/failing_test.rb"], message: "Running all tests")
subject.run_on_changes(["test/succeeding_test.rb"])
subject.run_on_changes(["test/succeeding_test.rb"])
end
it "doesn't call #run_all if the changed specs pass without failing" do
- runner.should_receive(:run).with(["test/succeeding_test.rb"]).and_return(true)
- runner.should_not_receive(:run).with(["test/succeeding_test.rb", "test/test_old.rb", "test/unit/error/error_test.rb", "test/unit/failing_test.rb"], message: "Running all tests")
+ expect(runner).to receive(:run).with(["test/succeeding_test.rb"]).and_return(true)
+ expect(runner).to_not receive(:run).with(["test/succeeding_test.rb", "test/test_old.rb", "test/unit/error/error_test.rb", "test/unit/failing_test.rb"], message: "Running all tests")
subject.run_on_changes(["test/succeeding_test.rb"])
end
end
@@ -133,8 +133,8 @@
subject { described_class.new(all_after_pass: false) }
it "doesn't call #run_all if the changed specs pass after failing but the :all_after_pass option is false" do
- runner.should_receive(:run).with(["test/succeeding_test.rb"]).and_return(false, true)
- runner.should_not_receive(:run).with(["test/succeeding_test.rb", "test/test_old.rb", "test/unit/error/error_test.rb", "test/unit/failing_test.rb"], message: "Running all tests")
+ expect(runner).to receive(:run).with(["test/succeeding_test.rb"]).and_return(false, true)
+ expect(runner).to_not receive(:run).with(["test/succeeding_test.rb", "test/test_old.rb", "test/unit/error/error_test.rb", "test/unit/failing_test.rb"], message: "Running all tests")
subject.run_on_changes(["test/succeeding_test.rb"])
subject.run_on_changes(["test/succeeding_test.rb"])
@@ -145,13 +145,13 @@
subject { described_class.new(all_after_pass: false) }
it "keeps failed specs and rerun later by default" do
- runner.should_receive(:run).with(["test/unit/error/error_test.rb", "test/unit/failing_test.rb"]).and_return(false)
+ expect(runner).to receive(:run).with(["test/unit/error/error_test.rb", "test/unit/failing_test.rb"]).and_return(false)
subject.run_on_changes(["test/unit"])
- runner.should_receive(:run).with(["test/succeeding_test.rb", "test/unit/error/error_test.rb", "test/unit/failing_test.rb"]).and_return(true)
+ expect(runner).to receive(:run).with(["test/succeeding_test.rb", "test/unit/error/error_test.rb", "test/unit/failing_test.rb"]).and_return(true)
subject.run_on_changes(["test/succeeding_test.rb"])
- runner.should_receive(:run).with(["test/succeeding_test.rb"]).and_return(true)
+ expect(runner).to receive(:run).with(["test/succeeding_test.rb"]).and_return(true)
subject.run_on_changes(["test/succeeding_test.rb"])
end
end
@@ -160,13 +160,13 @@
subject { described_class.new(all_after_pass: false, keep_failed: false) }
it "doesn't keep failed specs" do
- runner.should_receive(:run).with(["test/unit/error/error_test.rb", "test/unit/failing_test.rb"]).and_return(false)
+ expect(runner).to receive(:run).with(["test/unit/error/error_test.rb", "test/unit/failing_test.rb"]).and_return(false)
subject.run_on_changes(["test/unit"])
- runner.should_receive(:run).with(["test/succeeding_test.rb"]).and_return(true)
+ expect(runner).to receive(:run).with(["test/succeeding_test.rb"]).and_return(true)
subject.run_on_changes(["test/succeeding_test.rb"])
- runner.should_receive(:run).with(["test/succeeding_test.rb"]).and_return(true)
+ expect(runner).to receive(:run).with(["test/succeeding_test.rb"]).and_return(true)
subject.run_on_changes(["test/succeeding_test.rb"])
end
end
View
@@ -1,18 +1,20 @@
-ENV['GUARD_ENV'] = 'test'
+require 'rspec'
+require 'guard/test'
if ENV['CI']
require 'coveralls'
Coveralls.wear!
end
-require 'rspec'
-require 'guard/test'
-
RSpec.configure do |config|
config.color_enabled = true
- config.filter_run focus: true
- config.run_all_when_everything_filtered = true
+ config.order = :random
+ config.filter_run focus: ENV['CI'] != 'true'
config.treat_symbols_as_metadata_keys_with_true_values = true
+ config.run_all_when_everything_filtered = true
+ config.expect_with :rspec do |c|
+ c.syntax = :expect
+ end
config.before(:all) do
@lib_path = Pathname.new(File.expand_path('../../lib/', __FILE__))
View
@@ -1 +1 @@
-require 'rubygems'
+require 'test/unit/autorunner'

0 comments on commit afa277b

Please sign in to comment.