Skip to content
This repository has been archived by the owner on May 9, 2022. It is now read-only.

Commit

Permalink
Merge pull request #26 from github/rspec-update
Browse files Browse the repository at this point in the history
Update rspec so that 'rake spec' works again
  • Loading branch information
spraints authored Mar 3, 2020
2 parents 175fe8a + 99cc0e2 commit bb8ce72
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 33 deletions.
25 changes: 15 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,27 @@ PATH
GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.2.5)
diff-lcs (1.3)
docker-api (1.34.2)
excon (>= 0.47.0)
multi_json
excon (0.66.0)
msgpack (1.0.3)
multi_json (1.13.1)
rake (12.3.3)
rspec (2.99.0)
rspec-core (~> 2.99.0)
rspec-expectations (~> 2.99.0)
rspec-mocks (~> 2.99.0)
rspec-core (2.99.2)
rspec-expectations (2.99.2)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.99.4)
rspec (3.9.0)
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
rspec-mocks (~> 3.9.0)
rspec-core (3.9.1)
rspec-support (~> 3.9.1)
rspec-expectations (3.9.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-mocks (3.9.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.2)
yajl-ruby (1.4.1)

PLATFORMS
Expand All @@ -33,7 +38,7 @@ PLATFORMS
DEPENDENCIES
hoosegow!
rake
rspec (~> 2.14, >= 2.14.1)
rspec (~> 3.9.0)

BUNDLED WITH
1.16.1
2 changes: 1 addition & 1 deletion hoosegow.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Gem::Specification.new do |s|
s.homepage = 'https://github.com/github/hoosegow'
s.required_ruby_version = ">= 1.9.3"
s.add_development_dependency 'rake'
s.add_development_dependency 'rspec', '>= 2.14.1', '~> 2.14'
s.add_development_dependency 'rspec', '~> 3.9.0'
s.add_runtime_dependency 'msgpack', '~> 1.0.0'
s.add_runtime_dependency 'yajl-ruby', '>= 1.1.0', '~> 1.1'
s.add_runtime_dependency 'docker-api', '~> 1.19'
Expand Down
16 changes: 8 additions & 8 deletions spec/hoosegow_docker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@

context 'unspecified' do
subject { described_class.new }
its(:volumes_for_bind) { should be_empty }
it { expect(subject.send(:volumes_for_bind)).to be_empty }
end

context 'empty' do
let(:volumes) { {} }
its(:volumes_for_bind) { should be_empty }
it { expect(subject.send(:volumes_for_bind)).to be_empty }
end

context 'with volumes' do
let(:volumes) { {
"/inside/path" => "/home/burke/data-for-container:rw",
"/other/path" => "/etc/shared-config",
} }
its(:volumes_for_bind) { should == [
it { expect(subject.send(:volumes_for_bind)).to eq([
"/home/burke/data-for-container:/inside/path:rw",
"/etc/shared-config:/other/path:ro",
] }
]) }
end
end

Expand Down Expand Up @@ -110,10 +110,10 @@
end

context "callbacks" do
let(:cb) { lambda { |info| } }
let(:cb) { double("callback") }

it "calls after_create" do
expect(cb).to receive(:call).with { |*args| args.first.is_a? Hash }
expect(cb).to receive(:call).with(instance_of(Hash))
docker = Hoosegow::Docker.new CONFIG.merge(:after_create => cb)
begin
docker.create_container CONFIG[:image_name]
Expand All @@ -124,7 +124,7 @@
end

it "calls after_start" do
expect(cb).to receive(:call).with { |*args| args.first.is_a? Hash }
expect(cb).to receive(:call).with(instance_of(Hash))
docker = Hoosegow::Docker.new CONFIG.merge(:after_start => cb)
begin
docker.create_container CONFIG[:image_name]
Expand All @@ -136,7 +136,7 @@
end

it "calls after_stop" do
expect(cb).to receive(:call).with { |*args| args.first.is_a? Hash }
expect(cb).to receive(:call).with(instance_of(Hash))
docker = Hoosegow::Docker.new CONFIG.merge(:after_stop => cb)
begin
docker.create_container CONFIG[:image_name]
Expand Down
29 changes: 15 additions & 14 deletions spec/hoosegow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
context "no_proxy option" do
it "runs directly if set" do
hoosegow = Hoosegow.new CONFIG.merge(:no_proxy => true)
hoosegow.stub :proxy_send => "not raboof"
hoosegow.render_reverse("foobar").should eq("raboof")
allow(hoosegow).to receive(:proxy_send).and_return("not raboof")
expect(hoosegow.render_reverse("foobar")).to eq("raboof")
end

it "runs via proxy if not set" do
hoosegow = Hoosegow.new CONFIG
hoosegow.stub :proxy_send => "not raboof"
hoosegow.render_reverse("foobar").should eq("not raboof")
allow(hoosegow).to receive(:proxy_send).and_return("not raboof")
expect(hoosegow.render_reverse("foobar")).to eq("not raboof")
hoosegow.cleanup
end
end
Expand Down Expand Up @@ -54,7 +54,7 @@
end

it "decodes a yield" do
block.should_receive(:call).with('a', 'b')
expect(block).to receive(:call).with('a', 'b')
proxy.receive(:stdout, MessagePack.pack([:yield, ['a', 'b']]))
end

Expand Down Expand Up @@ -83,12 +83,12 @@
end

it "decodes stdout" do
stdout.should_receive(:write).with('abc')
expect(stdout).to receive(:write).with('abc')
proxy.receive(:stdout, MessagePack.pack([:stdout, 'abc']))
end

it "decodes stderr" do
stderr.should_receive(:write).with('abc')
expect(stderr).to receive(:write).with('abc')
proxy.receive(:stderr, 'abc')
end

Expand All @@ -103,7 +103,7 @@
describe Hoosegow::Protocol::Inmate do
it "calls appropriate render method" do
inmate = double('inmate')
inmate.should_receive(:render).with('foobar').
expect(inmate).to receive(:render).with('foobar').
and_yield(:a, 1).
and_yield(:b, 2, 3).
and_return('raboof')
Expand Down Expand Up @@ -143,17 +143,19 @@ def inmate.render(s) ; raise 'boom' ; end
feed_stdin.write(MessagePack.pack(['render', ['foobar']]))

inmate = double('inmate')
inmate.should_receive(:render).with('foobar').and_return('raboof')
expect(inmate).to receive(:render).with('foobar').and_return('raboof')
stdout = StringIO.new
stdout.set_encoding('BINARY')
r,w = IO.pipe

timeout(2) { Hoosegow::Protocol::Inmate.run(:inmate => inmate, :stdin => stdin, :stdout => stdout, :intercepted => r) }
Timeout.timeout(2) do
Hoosegow::Protocol::Inmate.run(:inmate => inmate, :stdin => stdin, :stdout => stdout, :intercepted => r)
end
end

it "encodes stdout" do
inmate = double('inmate')
inmate.should_receive(:render).with('foobar').and_return('raboof')
expect(inmate).to receive(:render).with('foobar').and_return('raboof')

stdin = StringIO.new(MessagePack.pack(['render', ['foobar']]))
stdout = StringIO.new
Expand All @@ -163,8 +165,7 @@ def inmate.render(s) ; raise 'boom' ; end

Hoosegow::Protocol::Inmate.run(:inmate => inmate, :stdin => stdin, :stdout => stdout, :intercepted => r)

encoded_stdout = MessagePack.pack([:stdout, "STDOUT from somewhere\n"])
encoded_return = MessagePack.pack([:return, 'raboof'])
expect([encoded_stdout+encoded_return, encoded_return+encoded_stdout]).to include(stdout.string)
output = MessagePack::Unpacker.new(StringIO.new(stdout.string)).each.to_a
expect(output.sort).to eq([ ["return", "raboof"], ["stdout", "STDOUT from somewhere\n"] ])
end
end

0 comments on commit bb8ce72

Please sign in to comment.