Permalink
Browse files

Fixes for RSpec and Cucumber tests on Windows

* Do not load Berkshelf::API
* Add api_client and not_supported_on_windows tags to RSpec tests
* Add api_server tag to Cucumber features requiring Berkshelf::API
* Skip these tags on Windows
* Use && instead of ; in command line operations
* Rewrite checks using temporary directories
* Use double quotes when shelling out
* Remove stderr redirects to /dev/null
* Git on Windows does not create full path to tmpdir, do this in clone
* Ensure that there is a / in Mercurial URIs
* Work around Thor::Shell::Basic behaviour differences on Windows
* Disable Yard runs on Windows
  • Loading branch information...
1 parent 35148a0 commit 8b0e1f2e12bf838e0b27c557a13dc59f3cd07704 @rarenerd rarenerd committed Nov 26, 2013
View
18 Guardfile
@@ -4,19 +4,25 @@ guard 'spork' do
watch(%r{^features/support/}) { :cucumber }
end
-guard 'yard', stdout: '/dev/null', stderr: '/dev/null' do
- watch(%r{app/.+\.rb})
- watch(%r{lib/.+\.rb})
- watch(%r{ext/.+\.c})
+unless RUBY_PLATFORM =~ /mswin|mingw|windows/
+ guard 'yard', stdout: '/dev/null', stderr: '/dev/null' do
+ watch(%r{app/.+\.rb})
+ watch(%r{lib/.+\.rb})
+ watch(%r{ext/.+\.c})
+ end
end
-guard 'rspec', cli: '--color --drb --format Fuubar', all_on_start: false, all_after_pass: false do
+rspec_cli = '--color --drb --format Fuubar'
+rspec_cli += ' --tag ~@api_client --tag ~@not_supported_on_windows' if RUBY_PLATFORM =~ /mswin|mingw|windows/
+guard 'rspec', cli: rspec_cli, all_on_start: false, all_after_pass: false do
watch(%r{^spec/unit/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { 'spec' }
end
-guard 'cucumber', cli: '--drb --format pretty --tags ~@no_run --tags ~@wip', all_on_start: false, all_after_pass: false do
+cucumber_cli = '--drb --format pretty --tags ~@no_run --tags ~@wip'
+cucumber_cli += ' --tags ~@spawn --tags ~@api_server' if RUBY_PLATFORM =~ /mswin|mingw|windows/
+guard 'cucumber', cli: cucumber_cli, all_on_start: false, all_after_pass: false do
watch(%r{^features/.+\.feature$})
watch(%r{^features/support/.+$}) { 'features' }
watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
View
1 features/commands/apply.feature
@@ -1,3 +1,4 @@
+@api_server
Feature: berks apply
Scenario: Locking a cookbook version with dependencies
Given the cookbook store contains a cookbook "fake" "1.0.0" with dependencies:
View
1 features/commands/package.feature
@@ -1,3 +1,4 @@
+@api_server
Feature: berks package
Background:
* the cookbook store has the cookbooks:
View
1 features/commands/update.feature
@@ -1,3 +1,4 @@
+@api_server
Feature: berks update
Background:
* the cookbook store has the cookbooks:
View
1 features/lockfile.feature
@@ -1,3 +1,4 @@
+@api_server
Feature: Creating and reading the Berkshelf lockfile
Background:
* the cookbook store has the cookbooks:
View
12 features/support/env.rb
@@ -1,12 +1,16 @@
require 'spork'
+def windows?
+ !!(RUBY_PLATFORM =~ /mswin|mingw|windows/)
+end
+
Spork.prefork do
require 'aruba/cucumber'
require 'aruba/in_process'
require 'aruba/spawn_process'
require 'cucumber/rspec/doubles'
- require 'berkshelf/api/rspec'
- require 'berkshelf/api/cucumber'
+ require 'berkshelf/api/rspec' unless windows?
+ require 'berkshelf/api/cucumber' unless windows?
Dir['spec/support/**/*.rb'].each { |f| require File.expand_path(f) }
@@ -18,7 +22,7 @@
at_exit do
Berkshelf::RSpec::ChefServer.stop
- Berkshelf::API::RSpec::Server.stop
+ Berkshelf::API::RSpec::Server.stop unless windows?
end
Before do
@@ -50,7 +54,7 @@
]
Berkshelf::RSpec::ChefServer.start(port: CHEF_SERVER_PORT)
- Berkshelf::API::RSpec::Server.start(port: BERKS_API_PORT, endpoints: endpoints)
+ Berkshelf::API::RSpec::Server.start(port: BERKS_API_PORT, endpoints: endpoints) unless windows?
@aruba_io_wait_seconds = Cucumber::JRUBY ? 7 : 5
@aruba_timeout_seconds = Cucumber::JRUBY ? 35 : 15
View
2 lib/berkshelf/locations/git_location.rb
@@ -102,7 +102,7 @@ def git
def clone
tmp_clone = File.join(self.class.tmpdir, uri.gsub(/[\/:]/,'-'))
-
+ FileUtils.mkdir_p(File.join(File.split(tmp_clone).shift))
unless File.exists?(tmp_clone)
Berkshelf::Git.clone(uri, tmp_clone)
end
View
12 spec/spec_helper.rb
@@ -1,9 +1,13 @@
require 'spork'
+def windows?
+ !!(RUBY_PLATFORM =~ /mswin|mingw|windows/)
+end
+
Spork.prefork do
require 'rspec'
require 'webmock/rspec'
- require 'berkshelf/api/rspec'
+ require 'berkshelf/api/rspec' unless windows?
Dir['spec/support/**/*.rb'].each { |f| require File.expand_path(f) }
@@ -13,7 +17,7 @@
config.include Berkshelf::RSpec::ChefServer
config.include Berkshelf::RSpec::Git
config.include Berkshelf::RSpec::PathHelpers
- config.include Berkshelf::API::RSpec
+ config.include Berkshelf::API::RSpec unless windows?
config.expect_with :rspec do |c|
c.syntax = :expect
@@ -27,7 +31,7 @@
config.before(:suite) do
WebMock.disable_net_connect!(allow_localhost: true, net_http_connect_on_start: true)
Berkshelf::RSpec::ChefServer.start
- Berkshelf::API::RSpec::Server.start
+ Berkshelf::API::RSpec::Server.start unless windows?
Berkshelf.set_format(:null)
Berkshelf.ui.mute!
end
@@ -41,7 +45,7 @@
end
config.before(:each) do
- Berkshelf::API::RSpec::Server.clear_cache
+ Berkshelf::API::RSpec::Server.clear_cache unless windows?
clean_tmp_path
Berkshelf.initialize_filesystem
Berkshelf::CookbookStore.instance.initialize_filesystem
View
18 spec/support/git.rb
@@ -21,23 +21,23 @@ def generate_fake_git_remote(uri, options = {})
Dir.chdir(path) do
shell_out "git config receive.denyCurrentBranch ignore"
- shell_out "echo '# a change!' >> content_file"
+ shell_out "echo \"# a change!\" >> content_file"
shell_out "git add ."
- shell_out "git commit -am 'A commit.'"
+ shell_out "git commit -am \"A commit.\""
options[:tags].each do |tag|
- shell_out "echo '#{tag}' > content_file"
+ shell_out "echo \"#{tag}\" > content_file"
shell_out "git add content_file"
- shell_out "git commit -am '#{tag} content'"
- shell_out "git tag '#{tag}' 2> /dev/null"
+ shell_out "git commit -am \"#{tag} content\""
+ shell_out "git tag \"#{tag}\""
end if options[:tags]
options[:branches].each do |branch|
- shell_out "git checkout -b #{branch} master 2> /dev/null"
- shell_out "echo '#{branch}' > content_file"
+ shell_out "git checkout -b #{branch} master"
+ shell_out "echo \"#{branch}\" > content_file"
shell_out "git add content_file"
- shell_out "git commit -am '#{branch} content'"
- shell_out "git checkout master 2> /dev/null"
+ shell_out "git commit -am \"#{branch} content\""
+ shell_out "git checkout master"
end if options[:branches]
end
end
View
18 spec/support/mercurial.rb
@@ -8,7 +8,7 @@ module Mercurial
include Berkshelf::RSpec::PathHelpers
def mercurial_origin_for(repo, options = {})
- "file://localhost#{generate_fake_mercurial_remote(repo, options)}"
+ File.join("file://localhost", generate_fake_mercurial_remote(repo, options))
end
def generate_fake_mercurial_remote(uri, options = {})
@@ -19,21 +19,21 @@ def generate_fake_mercurial_remote(uri, options = {})
Dir.chdir(repo_path) do
ENV['HGUSER'] = 'test_user'
shell_out "hg init"
- shell_out "echo '# a change!' >> content_file"
+ shell_out "echo \"# a change!\" >> content_file"
if options[:is_cookbook]
- shell_out "echo '#cookbook' >> metadata.rb"
+ shell_out "echo \"#cookbook\" >> metadata.rb"
end
shell_out "hg add ."
- shell_out "hg commit -m 'A commit.'"
+ shell_out "hg commit -m \"A commit.\""
options[:tags].each do |tag|
- shell_out "echo '#{tag}' > content_file"
- shell_out "hg commit -m '#{tag} content'"
- shell_out "hg tag '#{tag}'"
+ shell_out "echo \"#{tag}\" > content_file"
+ shell_out "hg commit -m \"#{tag} content\""
+ shell_out "hg tag \"#{tag}\""
end if options.has_key? :tags
options[:branches].each do |branch|
shell_out "hg branch #{branch}"
- shell_out "echo '#{branch}' > content_file"
- shell_out "hg commit -m '#{branch} content'"
+ shell_out "echo \"#{branch}\" > content_file"
+ shell_out "hg commit -m \"#{branch} content\""
shell_out "hg up default"
end if options.has_key? :branches
end
View
2 spec/unit/berkshelf/api_client_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Berkshelf::APIClient do
+describe Berkshelf::APIClient, :api_client do
let(:instance) { described_class.new("http://localhost:26210") }
describe "#universe" do
View
14 spec/unit/berkshelf/berksfile_spec.rb
@@ -68,7 +68,13 @@
end
it 'merges the default options into specified options' do
- subject.should_receive(:add_dependency).with(name, constraint, path: '/Users/reset', group: [])
+ subject.should_receive(:add_dependency)do |arg_name, arg_constraint, arg_options|
+ expect(arg_name).to eq(name)
+ expect(arg_constraint).to eq(constraint)
+ expect(arg_options[:path]).to match(%r{/Users/reset})
+ expect(arg_options[:group]).to eq([])
+ end
+
subject.cookbook(name, constraint, path: '/Users/reset')
end
@@ -560,15 +566,15 @@
context 'when the dependency does not exist' do
it 'raises a CookbookNotFound exception' do
expect {
- subject.package('non-existent', output: '/tmp')
+ subject.package('non-existent', output: Dir.tmpdir)
}.to raise_error(Berkshelf::CookbookNotFound)
end
end
context 'when the dependency exists' do
let(:dependency) { double('dependency') }
let(:cached) { double('cached', path: '/foo/bar', cookbook_name: 'cookbook') }
- let(:options) { { output: '/tmp' } }
+ let(:options) { { output: Dir.tmpdir } }
before do
FileUtils.stub(:cp_r)
@@ -583,7 +589,7 @@
end
it 'returns the output path' do
- expect(subject.package('non-existent', options)).to eq('/tmp/non-existent.tar.gz')
+ expect(subject.package('non-existent', options)).to eq(File.join(Dir.tmpdir, 'non-existent.tar.gz'))
end
end
end
View
2 spec/unit/berkshelf/config_spec.rb
@@ -37,7 +37,7 @@
end
it "points to a location within it" do
- expect(Berkshelf::Config.path).to eq('/tmp/config.json')
+ expect(Berkshelf::Config.path).to match(%r{/tmp/config.json})
end
end
end
View
2 spec/unit/berkshelf/locations/git_location_spec.rb
@@ -81,7 +81,7 @@
it 'raises a CookbookNotFound error' do
subject.stub(:clone).and_return {
FileUtils.mkdir_p(fake_remote)
- Dir.chdir(fake_remote) { |dir| `git init; echo hi > README; git add README; git commit README -m 'README'`; dir }
+ Dir.chdir(fake_remote) { |dir| `git init && echo hi > README && git add README && git commit README -m 'README'`; dir }
}
expect { subject.download }.to raise_error(Berkshelf::CookbookNotFound)
View
2 spec/unit/berkshelf/resolver/graph_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Berkshelf::Resolver::Graph do
+describe Berkshelf::Resolver::Graph, :not_supported_on_windows do
subject { described_class.new }
describe "#populate" do
View
8 spec/unit/berkshelf/ui_spec.rb
@@ -29,7 +29,7 @@
subject.stub(:quiet?).and_return(true)
end
- it 'does not output anything' do
+ it 'does not output anything', :not_supported_on_windows do
stdout.should_not_receive(:puts)
subject.say 'message'
end
@@ -66,7 +66,7 @@
end
it 'prints to stdout' do
- stdout.should_receive(:puts).with("\e[1m\e[32m 5\e[0m message")
+ stdout.should_receive(:puts).with(windows? ? " 5 message" : "\e[1m\e[32m 5\e[0m message")
stdout.should_receive(:flush).with(no_args())
subject.say_status 5, 'message'
end
@@ -112,7 +112,7 @@
subject.stub(:quiet?).and_return(true)
end
- it 'does not output anything' do
+ it 'does not output anything', :not_supported_on_windows do
stdout.should_not_receive(:puts)
subject.error 'error!'
end
@@ -124,7 +124,7 @@
end
it 'prints to stderr' do
- stderr.should_receive(:puts).with("\e[31merror!\e[0m")
+ stderr.should_receive(:puts).with(windows? ? "error!" : "\e[31merror!\e[0m")
subject.error 'error!'
end
end

0 comments on commit 8b0e1f2

Please sign in to comment.