Skip to content

Commit

Permalink
Call parent method_missing unconditionally for 12.3 resource support
Browse files Browse the repository at this point in the history
  • Loading branch information
jkeiser committed Aug 18, 2015
1 parent 53351ba commit e18d8a4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 31 deletions.
10 changes: 7 additions & 3 deletions lib/cheffish/rspec/recipe_run_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ def client

# Call into the rspec example's let variables and other methods
@client.define_singleton_method(:method_missing) do |name, *args, &block|
if example.respond_to?(name)
example.public_send(name, *args, &block)
else
begin
super(name, *args, &block)
rescue NameError
if example.respond_to?(name)
example.public_send(name, *args, &block)
else
raise
end
end
end
# This is called by respond_to?, and is required to make sure the
Expand Down
56 changes: 28 additions & 28 deletions spec/integration/rspec/converge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,107 +4,107 @@
describe 'Cheffish::RSpec::ChefRunSupport' do
extend Cheffish::RSpec::ChefRunSupport

let(:tempfile) { Tempfile.new('test') }
let(:temp_file) { Tempfile.new('test') }

context "#recipe" do
it "recipe { file ... } updates the file" do
result = recipe {
file tempfile.path do
file temp_file.path do
content 'test'
end
}
expect(result.updated?).to be_falsey
expect(IO.read(tempfile.path)).to eq ''
expect(IO.read(temp_file.path)).to eq ''
end

it "recipe 'file ...' does not update the file" do
result = recipe <<-EOM
file tempfile.path do
file temp_file.path do
content 'test'
end
EOM
expect(result.updated?).to be_falsey
expect(IO.read(tempfile.path)).to eq ''
expect(IO.read(temp_file.path)).to eq ''
end

it "recipe 'file ...' with file and line number does not update the file" do
result = recipe(<<-EOM, __FILE__, __LINE__+1)
file tempfile.path do
file temp_file.path do
content 'test'
end
EOM
expect(result.updated?).to be_falsey
expect(IO.read(tempfile.path)).to eq ''
expect(IO.read(temp_file.path)).to eq ''
end
end

context "#converge" do
it "converge { file ... } updates the file" do
result = converge {
file tempfile.path do
file temp_file.path do
content 'test'
end
}
expect(result.updated?).to be_truthy
expect(IO.read(tempfile.path)).to eq 'test'
expect(IO.read(temp_file.path)).to eq 'test'
end

it "converge 'file ...' updates the file" do
result = converge <<-EOM
file tempfile.path do
file temp_file.path do
content 'test'
end
EOM
expect(result.updated?).to be_truthy
expect(IO.read(tempfile.path)).to eq 'test'
expect(IO.read(temp_file.path)).to eq 'test'
end

it "converge 'file ...' with file and line number updates the file" do
result = converge(<<-EOM, __FILE__, __LINE__+1)
file tempfile.path do
file temp_file.path do
content 'test'
end
EOM
expect(result.updated?).to be_truthy
expect(IO.read(tempfile.path)).to eq 'test'
expect(IO.read(temp_file.path)).to eq 'test'
end
end

context "#expect_recipe" do
it "expect_recipe { file ... }.to be_updated updates the file, and be_idempotent does not fail" do
expect_recipe {
file tempfile.path do
file temp_file.path do
content 'test'
end
}.to be_updated.and be_idempotent

expect(IO.read(tempfile.path)).to eq 'test'
expect(IO.read(temp_file.path)).to eq 'test'
end

it "expect_recipe 'file ...'.to be_updated updates the file, and be_idempotent does not fail" do
expect_recipe(<<-EOM).to be_updated.and be_idempotent
file tempfile.path do
file temp_file.path do
content 'test'
end
EOM

expect(IO.read(tempfile.path)).to eq 'test'
expect(IO.read(temp_file.path)).to eq 'test'
end

it "expect_recipe('file ...', file, line).to be_updated updates the file, and be_idempotent does not fail" do
expect_recipe(<<-EOM, __FILE__, __LINE__+1).to be_updated.and be_idempotent
file tempfile.path do
file temp_file.path do
content 'test'
end
EOM

expect(IO.read(tempfile.path)).to eq 'test'
expect(IO.read(temp_file.path)).to eq 'test'
end

it "expect_recipe { file ... }.to be_up_to_date fails" do
expect {
expect_recipe {
file tempfile.path do
file temp_file.path do
content 'test'
end
}.to be_up_to_date
Expand All @@ -129,29 +129,29 @@
context "#expect_converge" do
it "expect_converge { file ... }.not_to raise_error updates the file" do
expect_converge {
file tempfile.path do
file temp_file.path do
content 'test'
end
}.not_to raise_error
expect(IO.read(tempfile.path)).to eq 'test'
expect(IO.read(temp_file.path)).to eq 'test'
end

it "expect_converge('file ...').not_to raise_error updates the file" do
expect_converge(<<-EOM).not_to raise_error
file tempfile.path do
file temp_file.path do
content 'test'
end
EOM
expect(IO.read(tempfile.path)).to eq 'test'
expect(IO.read(temp_file.path)).to eq 'test'
end

it "expect_converge('file ...', file, line).not_to raise_error updates the file" do
expect_converge(<<-EOM, __FILE__, __LINE__+1).not_to raise_error
file tempfile.path do
file temp_file.path do
content 'test'
end
EOM
expect(IO.read(tempfile.path)).to eq 'test'
expect(IO.read(temp_file.path)).to eq 'test'
end

it "expect_converge { raise 'oh no' }.to raise_error passes" do
Expand All @@ -173,11 +173,11 @@

it "converge with a file resource referencing let_variable accesses let_variable" do
converge {
file tempfile.path do
file temp_file.path do
content let_variable
end
}
expect(IO.read(tempfile.path)).to eq 'test'
expect(IO.read(temp_file.path)).to eq 'test'
end
end
end

0 comments on commit e18d8a4

Please sign in to comment.