Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add the `:rubygems` options for project that doesn't use Bundler

  • Loading branch information...
commit 5cf467168060cc9e86a36c34b8b2906c885ef31a 1 parent 3707934
@rymai rymai authored
View
6 CHANGELOG.md
@@ -1,3 +1,9 @@
+## Master
+
+### New feature:
+
+- [#20](https://github.com/guard/guard-test/issues/20): Add the `:rubygems` options for project that doesn't use Bundler. ([@rymai][])
+
## 0.4.3 - December 19, 2011 - ([@rymai][])
### Bug fix:
View
2  Gemfile
@@ -10,6 +10,8 @@ gem 'guard-rspec', :git => "git://github.com/guard/guard-rspec.git"
require 'rbconfig'
platforms :ruby do
+ gem 'rb-readline'
+
if RbConfig::CONFIG['target_os'] =~ /darwin/i
gem 'rb-fsevent'
gem 'ruby_gntp'
View
1  Guardfile
@@ -7,7 +7,6 @@ group 'specs' do
end
group 'tests' do
-
guard :test do
watch(%r{lib/(.+)\.rb}) { |m| "test/#{m[1]}_test.rb" }
watch(%r{test/.+_test\.rb})
View
1  README.md
@@ -56,6 +56,7 @@ Please read the [Guard documentation](https://github.com/guard/guard#readme) for
### Available options
* `bundler` (`Boolean`) - Whether or not to use `bundle exec` to run tests. Default to `true` if a you have a Gemfile in the current directory.
+* `rubygems` (`Boolean`) - Whether or not to require rubygems (if bundler isn't used) when running the tests. Default to `false`.
* `rvm` (`Array<String>`) - Directly run your specs against multiple Rubies. Default to `nil`.
* `drb` (`Boolean`) - Run your tests with [`spork-testunit`](https://github.com/timcharper/spork-testunit). Default to `false`.
* `cli` (`String`) - Pass arbitrary CLI arguments to the command that runs the tests. Default to `nil`.
View
14 lib/guard/test/runner.rb
@@ -6,10 +6,11 @@ class Runner
def initialize(options = {})
@options = {
- :bundler => File.exist?("#{Dir.pwd}/Gemfile"),
- :rvm => [],
- :drb => false,
- :cli => ""
+ :bundler => File.exist?("#{Dir.pwd}/Gemfile"),
+ :rubygems => false,
+ :rvm => [],
+ :drb => false,
+ :cli => ""
}.merge(options)
end
@@ -28,6 +29,10 @@ def bundler?
@bundler
end
+ def rubygems?
+ !bundler? && @options[:rubygems]
+ end
+
def drb?
if @drb.nil?
@drb = @options[:drb]
@@ -54,6 +59,7 @@ def test_unit_command(paths)
end
cmd_parts << "-Itest"
cmd_parts << "-r bundler/setup" if bundler?
+ cmd_parts << "-rubygems" if rubygems?
unless drb?
cmd_parts << "-r #{File.expand_path("../guard_test_runner", __FILE__)}"
View
81 spec/guard/test/runner_spec.rb
@@ -8,29 +8,67 @@
it "sets default options" do
runner = described_class.new
runner.instance_variable_get(:@options)[:bundler].should be_true
+ runner.instance_variable_get(:@options)[:rubygems].should be_false
runner.instance_variable_get(:@options)[:rvm].should be_empty
runner.instance_variable_get(:@options)[:drb].should be_false
runner.instance_variable_get(:@options)[:cli].should eql ""
end
- it "sets option :bundler" do
- runner = described_class.new(:bundler => true)
- runner.instance_variable_get(:@options)[:bundler].should be_true
+ describe ":bundler option" do
+ context "with the :drb option set to true" do
+ it "uses drb but not bundler" do
+ runner = described_class.new(:drb => true, :bundler => true)
+ runner.should be_drb
+ runner.should_not be_bundler
+ end
+ end
+
+ context "with the :drb option set to false" do
+ it "uses bundler but not drb" do
+ runner = described_class.new(:drb => false, :bundler => true)
+ runner.should_not be_drb
+ runner.should be_bundler
+ end
+ end
+ end
+
+ describe ":rubygems option" do
+ context "with the :bundler option set to true" do
+ it "uses bundler but not rubygems" do
+ runner = described_class.new(:bundler => true, :rubygems => true)
+ runner.should be_bundler
+ runner.should_not be_rubygems
+ end
+ end
+
+ context "with the :bundler option set to false" do
+ it "uses rubygems but not bundler" do
+ runner = described_class.new(:bundler => false, :rubygems => true)
+ runner.should_not be_bundler
+ runner.should be_rubygems
+ end
+ end
end
- it "sets option :rvm" do
- runner = described_class.new(:rvm => '1.9.2')
- runner.instance_variable_get(:@options)[:rvm].should eql '1.9.2'
+ describe ":rvm option" do
+ it "sets the option in the instance @options hash" do
+ runner = described_class.new(:rvm => '1.9.2')
+ runner.instance_variable_get(:@options)[:rvm].should eq '1.9.2'
+ end
end
- it "sets option :drb" do
- runner = described_class.new(:drb => true)
- runner.instance_variable_get(:@options)[:drb].should be_true
+ describe ":drb option" do
+ it "uses drb" do
+ runner = described_class.new(:drb => true)
+ runner.should be_drb
+ end
end
- it "sets option :cli" do
- runner = described_class.new(:cli => '--show-detail-immediately')
- runner.instance_variable_get(:@options)[:cli].should eql '--show-detail-immediately'
+ describe ":cli option" do
+ it "sets the option in the instance @options hash" do
+ runner = described_class.new(:cli => '--show-detail-immediately')
+ runner.instance_variable_get(:@options)[:cli].should eq '--show-detail-immediately'
+ end
end
end
end
@@ -114,6 +152,23 @@
subject.run(["test/succeeding_test.rb"])
end
end
+
+ context "when the :rubygems option set to true (and :bundler to false) on initialize" do
+ subject do
+ runner = described_class.new(:bundler => false, :rubygems => true)
+ runner
+ end
+
+ it "runs without bundler and require rubygems" do
+ subject.should_receive(:system).with(
+ "ruby -Itest -rubygems -r #{@lib_path.join('guard/test/guard_test_runner')} " \
+ "-e \"%w[test/succeeding_test.rb].each { |p| load p }\" " \
+ "\"./test/succeeding_test.rb\" --use-color --runner=guard"
+ )
+
+ subject.run(["test/succeeding_test.rb"])
+ end
+ end
context "when no :runner option was given on initialize" do
subject do
@@ -129,7 +184,7 @@
dev_null { subject.run(["test/unit/error/error_test.rb", "test/unit/failing_test.rb"]) }
end
- it "runs with the --runner options set to 'guard-default' and require default_guard_test_runner" do
+ it "runs with the --runner options set to 'guard' and require default_guard_test_runner" do
subject.should_receive(:system).with(
"bundle exec " \
"ruby -Itest -r bundler/setup " \
Please sign in to comment.
Something went wrong with that request. Please try again.