Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chef-3020 Fix specs on Ruby 1.8.7 #278

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion chef/spec/functional/knife/exec_spec.rb
Expand Up @@ -43,7 +43,9 @@
@server.stop
end

it "executes a script in the context of the shef main context" do
pending "executes a script in the context of the shef main context", :ruby_18_only

it "executes a script in the context of the shef main context", :ruby_19_only do
@node = Chef::Node.new
@node.name("ohai-world")
response = {"rows" => [@node],"start" => 0,"total" => 1}
Expand Down
2 changes: 2 additions & 0 deletions chef/spec/spec_helper.rb
Expand Up @@ -67,6 +67,8 @@ module Shef
# Add jruby filters here
config.filter_run_excluding :windows_only => true unless windows?
config.filter_run_excluding :unix_only => true unless unix?
config.filter_run_excluding :ruby_18_only => true unless ruby_18?
config.filter_run_excluding :ruby_19_only => true unless ruby_19?
config.filter_run_excluding :requires_root => true unless ENV['USER'] == 'root'
config.filter_run_excluding :requires_unprivileged_user => true if ENV['USER'] == 'root'

Expand Down
20 changes: 20 additions & 0 deletions chef/spec/support/chef_helpers.rb
Expand Up @@ -30,3 +30,23 @@
def sha256_checksum(path)
Digest::SHA256.hexdigest(File.read(path))
end

# From Ruby 1.9.2+
# Here for backwards compatibility with Ruby 1.8.7
# http://rubydoc.info/stdlib/tmpdir/1.9.2/Dir/Tmpname
def make_tmpname(prefix_suffix, n)
case prefix_suffix
when String
prefix = prefix_suffix
suffix = ""
when Array
prefix = prefix_suffix[0]
suffix = prefix_suffix[1]
else
raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
end
t = Time.now.strftime("%Y%m%d")
path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
path << "-#{n}" if n
path << suffix
end
2 changes: 1 addition & 1 deletion chef/spec/support/shared/functional/directory_resource.rb
Expand Up @@ -76,7 +76,7 @@ def denied_acl(sid, expected_perms)

shared_context Chef::Resource::Directory do
let(:path) do
File.join(Dir.tmpdir, Dir::Tmpname.make_tmpname(directory_base, nil))
File.join(Dir.tmpdir, make_tmpname(directory_base, nil))
end

after(:each) do
Expand Down
2 changes: 1 addition & 1 deletion chef/spec/support/shared/functional/file_resource.rb
Expand Up @@ -124,7 +124,7 @@ def denied_acl(sid, expected_perms)

shared_context Chef::Resource::File do
let(:path) do
File.join(Dir.tmpdir, Dir::Tmpname.make_tmpname(file_base, nil))
File.join(Dir.tmpdir, make_tmpname(file_base, nil))
end

after(:each) do
Expand Down