spec/etcd/readme_spec.rb in etcd-0.2.2 vs spec/etcd/readme_spec.rb in etcd-0.2.3
- old
+ new
@@ -2,10 +2,18 @@
require 'spec_helper'
describe 'Etcd specs for the main etcd README examples' do
+ before(:all) do
+ start_daemon
+ end
+
+ after(:all) do
+ stop_daemon
+ end
+
let(:client) do
Etcd.client
end
shared_examples 'response with valid node data' do |action|
@@ -53,11 +61,11 @@
end
context 'set a key named "/message"' do
before(:all) do
- @response = Etcd.client.set('/message', value: 'PinkFloyd')
+ @response = etcd_client.set('/message', value: 'PinkFloyd')
end
it_should_behave_like 'response with valid http headers'
it_should_behave_like 'response with valid node data'
@@ -67,12 +75,12 @@
end
context 'get a key named "/message"' do
before(:all) do
- Etcd.client.set('/message', value: 'PinkFloyd')
- @response = Etcd.client.get('/message')
+ etcd_client.set('/message', value: 'PinkFloyd')
+ @response = etcd_client.get('/message')
end
it_should_behave_like 'response with valid http headers'
it_should_behave_like 'response with valid node data'
@@ -82,12 +90,12 @@
end
context 'change the value of a key named "/message"' do
before(:all) do
- Etcd.client.set('/message', value: 'World')
- @response = Etcd.client.set('/message', value: 'PinkFloyd')
+ etcd_client.set('/message', value: 'World')
+ @response = etcd_client.set('/message', value: 'PinkFloyd')
end
it_should_behave_like 'response with valid http headers'
it_should_behave_like 'response with valid node data'
@@ -97,13 +105,13 @@
end
context 'delete a key named "/message"' do
before(:all) do
- Etcd.client.set('/message', value: 'World')
- Etcd.client.set('/message', value: 'PinkFloyd')
- @response = Etcd.client.delete('/message')
+ etcd_client.set('/message', value: 'World')
+ etcd_client.set('/message', value: 'PinkFloyd')
+ @response = etcd_client.delete('/message')
end
it 'should set the return action to SET' do
expect(@response.action).to eq('delete')
end
@@ -113,13 +121,13 @@
end
context 'using ttl a key named "/message"' do
before(:all) do
- Etcd.client.set('/message', value: 'World')
+ etcd_client.set('/message', value: 'World')
@set_time = Time.now
- @response = Etcd.client.set('/message', value: 'PinkFloyd', ttl: 5)
+ @response = etcd_client.set('/message', value: 'PinkFloyd', ttl: 5)
end
it_should_behave_like 'response with valid http headers'
it_should_behave_like 'response with valid node data'
@@ -136,24 +144,25 @@
end
it 'should throw exception after the expiration time' do
sleep 8
expect do
- Etcd.client.get('/message')
+ client.get('/message')
end.to raise_error
end
end
context 'waiting for a change against a key named "/message"' do
before(:all) do
- Etcd.client.set('/message', value: 'foo')
+ etcd_client.set('/message', value: 'foo')
thr = Thread.new do
- @response = Etcd.client.watch('/message')
+ @response = etcd_client.watch('/message')
end
- Etcd.client.set('/message', value: 'PinkFloyd')
+ sleep 1
+ etcd_client.set('/message', value: 'PinkFloyd')
thr.join
end
it_should_behave_like 'response with valid http headers'
it_should_behave_like 'response with valid node data'
@@ -170,11 +179,11 @@
end
context 'atomic in-order keys' do
before(:all) do
- @response = Etcd.client.create_in_order('/queue', value: 'PinkFloyd')
+ @response = etcd_client.create_in_order('/queue', value: 'PinkFloyd')
end
it_should_behave_like 'response with valid http headers'
it_should_behave_like 'response with valid node data', :create
@@ -210,11 +219,11 @@
end
context 'directory with ttl' do
before(:all) do
- @response = Etcd.client.set('/directory', dir: true, ttl: 4)
+ @response = etcd_client.set('/directory', dir: true, ttl: 4)
end
it 'should create a directory' do
expect(client.get('/directory')).to be_directory
end
@@ -298,11 +307,11 @@
end
context 'hidden nodes' do
before(:all) do
- Etcd.client.set('/_message', value: 'Hello Hidden World')
- Etcd.client.set('/message', value: 'Hello World')
+ etcd_client.set('/_message', value: 'Hello Hidden World')
+ etcd_client.set('/message', value: 'Hello World')
end
it 'should not be visible in directory listing' do
expect(client.get('/').children.map(&:key)).to_not include('_message')
end