cistern 2.2.3 → 2.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  module Cistern
2
2
  module WaitFor
3
- def self.wait_for(timeout = Cistern.timeout, interval = Cistern.poll_interval, &block)
3
+ def self.wait_for(timeout = Cistern.timeout, interval = Cistern.poll_interval, &_block)
4
4
  duration = 0
5
5
  start = Time.now
6
6
 
@@ -12,11 +12,11 @@ module Cistern
12
12
  if duration > timeout
13
13
  false
14
14
  else
15
- { :duration => duration }
15
+ { duration: duration }
16
16
  end
17
17
  end
18
18
 
19
- def self.wait_for!(*arg)
19
+ def self.wait_for!(*_arg)
20
20
  wait_for
21
21
  end
22
22
  end
@@ -1,3 +1,3 @@
1
1
  module Cistern
2
- VERSION = "2.2.3"
2
+ VERSION = '2.2.4'
3
3
  end
@@ -23,10 +23,10 @@ module Cistern
23
23
  end
24
24
 
25
25
  def timeout_error
26
- @timeout_error || self.const_defined?(:Timeout) && self.const_get(:Timeout) || ::Timeout::Error
26
+ @timeout_error || self.const_defined?(:Timeout) && const_get(:Timeout) || ::Timeout::Error
27
27
  end
28
28
 
29
- def wait_for(timeout = self.timeout, interval = self.poll_interval, &block)
29
+ def wait_for(timeout = self.timeout, interval = poll_interval, &_block)
30
30
  duration = 0
31
31
  start = Time.now
32
32
 
@@ -38,8 +38,8 @@ module Cistern
38
38
  duration > timeout ? false : duration
39
39
  end
40
40
 
41
- def wait_for!(timeout = self.timeout, interval = self.poll_interval, &block)
42
- wait_for(timeout, interval, &block) || raise(timeout_error, "wait_for(#{timeout}) exceeded")
41
+ def wait_for!(timeout = self.timeout, interval = poll_interval, &block)
42
+ wait_for(timeout, interval, &block) || fail(timeout_error, "wait_for(#{timeout}) exceeded")
43
43
  end
44
44
  end
45
45
  end
data/lib/cistern.rb CHANGED
@@ -4,7 +4,6 @@ require 'cistern/version'
4
4
  require 'time'
5
5
 
6
6
  module Cistern
7
-
8
7
  Error = Class.new(StandardError)
9
8
  Timeout = Class.new(Error)
10
9
 
@@ -27,7 +26,9 @@ module Cistern
27
26
 
28
27
  require 'cistern/formatter'
29
28
 
30
- def self.formatter=(formatter); @formatter = formatter; end
29
+ def self.formatter=(formatter)
30
+ @formatter = formatter
31
+ end
31
32
 
32
33
  def self.formatter
33
34
  @formatter ||= Cistern::Formatter.default
@@ -41,10 +42,8 @@ module Cistern
41
42
  @deprecation_warnings = status
42
43
  end
43
44
 
44
- def self.deprecation(message, source=caller[1])
45
- if deprecation_warnings?
46
- STDERR.puts("#{message}. (#{source})")
47
- end
45
+ def self.deprecation(message, source = caller[1])
46
+ STDERR.puts("#{message}. (#{source})") if deprecation_warnings?
48
47
  end
49
48
  end
50
49
 
data/spec/client_spec.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe "client" do
4
- context "with specific architecture" do
5
- it "allows module-based interfaces" do
3
+ RSpec.describe 'client' do
4
+ context 'with specific architecture' do
5
+ it 'allows module-based interfaces' do
6
6
  class ModuleClient
7
7
  include Cistern::Client.with(interface: :module)
8
8
  end
@@ -21,7 +21,7 @@ RSpec.describe "client" do
21
21
  identity :on
22
22
 
23
23
  def save
24
- self.identity % 3
24
+ identity % 3
25
25
  end
26
26
  end
27
27
 
@@ -29,7 +29,6 @@ RSpec.describe "client" do
29
29
  include ModuleClient::Collection
30
30
 
31
31
  model ModuleClient::Moon
32
-
33
32
  end
34
33
 
35
34
  expect(
@@ -37,17 +36,17 @@ RSpec.describe "client" do
37
36
  ).to eq(3)
38
37
 
39
38
  expect(ModuleClient.collections).to contain_exactly(ModuleClient::Moons)
40
- expect(ModuleClient.models).to contain_exactly(ModuleClient::Moon)
41
- expect(ModuleClient.requests).to contain_exactly(ModuleClient::Shoot)
39
+ expect(ModuleClient.models).to contain_exactly(ModuleClient::Moon)
40
+ expect(ModuleClient.requests).to contain_exactly(ModuleClient::Shoot)
42
41
 
43
42
  expect(
44
43
  ModuleClient.new.moons.new(on: 5).save
45
44
  ).to eq(2)
46
45
  end
47
46
 
48
- it "allows custom model interface" do
47
+ it 'allows custom model interface' do
49
48
  class AskClient
50
- include Cistern::Client.with(model: "Ask", interface: :module)
49
+ include Cistern::Client.with(model: 'Ask', interface: :module)
51
50
  end
52
51
 
53
52
  class AskClient::Model
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Cistern::Collection" do
3
+ describe 'Cistern::Collection' do
4
4
  class SampleService < Cistern::Service
5
5
  end
6
6
 
@@ -13,7 +13,7 @@ describe "Cistern::Collection" do
13
13
  model Drug
14
14
 
15
15
  def all
16
- self.load([{id: 1}, {id: 3, name: "tom"}, {id: 2}])
16
+ load([{ id: 1 }, { id: 3, name: 'tom' }, { id: 2 }])
17
17
  end
18
18
  end
19
19
 
@@ -21,47 +21,47 @@ describe "Cistern::Collection" do
21
21
  service_method :toes
22
22
  end
23
23
 
24
- it "should generate a default collection method" do
24
+ it 'should generate a default collection method' do
25
25
  expect(SampleService.new.drugs).not_to be_empty
26
26
  end
27
27
 
28
- it "should allow for a specific collection name" do
29
- expect(SampleService.new).to respond_to(:toes)
28
+ it 'should allow for a specific collection name' do
29
+ expect(SampleService.new).to respond_to(:toes)
30
30
  expect(SampleService.new).not_to respond_to(:tacs)
31
31
  end
32
32
 
33
- it "should give to_s" do
33
+ it 'should give to_s' do
34
34
  collection = Drugs.new
35
- expect(collection.to_s).not_to eq "[]"
36
- expect(collection.to_s.gsub(/:[^>]*/,'')).to eq(collection.all.to_s.gsub(/:[^>]*/,''))
35
+ expect(collection.to_s).not_to eq '[]'
36
+ expect(collection.to_s.gsub(/:[^>]*/, '')).to eq(collection.all.to_s.gsub(/:[^>]*/, ''))
37
37
  end
38
38
 
39
- it "should give size and count" do
39
+ it 'should give size and count' do
40
40
  expect(Drugs.new.size).to eq(3)
41
41
  expect(Drugs.new.count).to eq(3)
42
42
  end
43
43
 
44
- it "should give first" do
44
+ it 'should give first' do
45
45
  expect(Drugs.new.first).to eq(Drug.new(id: 1))
46
46
  end
47
47
 
48
- it "should give last" do
48
+ it 'should give last' do
49
49
  expect(Drugs.new.last).to eq(Drug.new(id: 2))
50
50
  end
51
51
 
52
- it "should reject" do
53
- expect(Drugs.new.reject{|m| m.id == 2}).to eq([Drug.new(id: 1), Drug.new(id: 3)])
52
+ it 'should reject' do
53
+ expect(Drugs.new.reject { |m| m.id == 2 }).to eq([Drug.new(id: 1), Drug.new(id: 3)])
54
54
  end
55
55
 
56
- it "should select" do
57
- expect(Drugs.new.select{|m| m.id == 2}).to eq([Drug.new(id: 2)])
56
+ it 'should select' do
57
+ expect(Drugs.new.select { |m| m.id == 2 }).to eq([Drug.new(id: 2)])
58
58
  end
59
59
 
60
- it "should slice" do
61
- expect(Drugs.new.slice(0,2)).to eq([Drug.new(id: 1), Drug.new(id: 3, name: "tom")])
60
+ it 'should slice' do
61
+ expect(Drugs.new.slice(0, 2)).to eq([Drug.new(id: 1), Drug.new(id: 3, name: 'tom')])
62
62
  end
63
63
 
64
- it "should ==" do
64
+ it 'should ==' do
65
65
  Drugs.new.all == Drugs.new.all
66
66
  end
67
67
  end
data/spec/dirty_spec.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Cistern::Model#dirty" do
3
+ describe 'Cistern::Model#dirty' do
4
4
  class DirtySpec < Sample::Model
5
5
  identity :id
6
6
 
@@ -12,25 +12,25 @@ describe "Cistern::Model#dirty" do
12
12
  end
13
13
  end
14
14
 
15
- it "should mark a existing record as dirty" do
16
- model = DirtySpec.new(id: 1, name: "steve")
15
+ it 'should mark a existing record as dirty' do
16
+ model = DirtySpec.new(id: 1, name: 'steve')
17
17
  expect(model.changed).to be_empty
18
18
 
19
- expect {
19
+ expect do
20
20
  model.properties = [1]
21
- }.to change { model.dirty? }.to(true)
21
+ end.to change { model.dirty? }.to(true)
22
22
 
23
23
  expect(model.changed).to eq(properties: [nil, [1]])
24
24
  expect(model.dirty_attributes).to eq(properties: [1])
25
25
 
26
- expect {
26
+ expect do
27
27
  model.properties = [2]
28
- }.to change { model.changed }.to(properties: [nil, [2]])
28
+ end.to change { model.changed }.to(properties: [nil, [2]])
29
29
  expect(model.dirty_attributes).to eq(properties: [2])
30
30
 
31
- expect {
31
+ expect do
32
32
  model.save
33
- }.to change { model.dirty? }.to(false)
33
+ end.to change { model.dirty? }.to(false)
34
34
 
35
35
  expect(model.changed).to eq({})
36
36
  expect(model.dirty_attributes).to eq({})
@@ -12,18 +12,18 @@ end
12
12
  class Inspectors < Sample::Collection
13
13
  model Inspector
14
14
 
15
- def all(options={})
15
+ def all(options = {})
16
16
  merge_attributes(options)
17
- self.load([{id: 1, name: "2"},{id: 3, name: "4"}])
17
+ load([{ id: 1, name: '2' }, { id: 3, name: '4' }])
18
18
  end
19
19
  end
20
20
 
21
21
  describe Cistern::Formatter::Default do
22
22
  before { Cistern.formatter = described_class }
23
23
 
24
- it "formats a model" do
24
+ it 'formats a model' do
25
25
  expect(
26
- Inspector.new(id: 1, name: "name").inspect
26
+ Inspector.new(id: 1, name: 'name').inspect
27
27
  ).to match(
28
28
  /<Inspector:0x[a-z0-9]+> {:id=>1, :name=>\"name\"}/
29
29
  )
@@ -31,7 +31,7 @@ describe Cistern::Formatter::Default do
31
31
  Anon.inspect
32
32
  end
33
33
 
34
- it "formats a collection" do
34
+ it 'formats a collection' do
35
35
  expect(
36
36
  Inspectors.new.all.inspect
37
37
  ).to match(
@@ -43,15 +43,15 @@ end
43
43
  describe Cistern::Formatter::AwesomePrint do
44
44
  before { Cistern.formatter = described_class }
45
45
 
46
- it "formats a model" do
46
+ it 'formats a model' do
47
47
  expect(
48
- Inspector.new(id: 1, name: "name").inspect
48
+ Inspector.new(id: 1, name: 'name').inspect
49
49
  ).to match(
50
50
  /(?x-mi:\#<Inspector:0x[0-9a-f]+>\ {\n\ \ \ \ \ \ :id\x1B\[0;37m\ =>\ \x1B\[0m\x1B\[1;34m1\x1B\[0m,\n\ \ \ \ :name\x1B\[0;37m\ =>\ \x1B\[0m\x1B\[0;33m"name"\x1B\[0m\n})/
51
51
  )
52
52
  end
53
53
 
54
- it "formats a collection" do
54
+ it 'formats a collection' do
55
55
  expect(Inspectors.new.all.inspect).to match(/Inspectors\s+{.*}$/m) # close enough
56
56
  end
57
57
  end
@@ -59,17 +59,17 @@ end
59
59
  describe Cistern::Formatter::Formatador do
60
60
  before { Cistern.formatter = described_class }
61
61
 
62
- it "formats a model" do
62
+ it 'formats a model' do
63
63
  Cistern.formatter = Cistern::Formatter::Formatador
64
64
 
65
- expect(Inspector.new(id: 1, name: "name").inspect).to eq(%q{ <Inspector
65
+ expect(Inspector.new(id: 1, name: 'name').inspect).to eq(' <Inspector
66
66
  id=1,
67
67
  name="name"
68
- >})
68
+ >')
69
69
  end
70
70
 
71
- it "formats a collection" do
72
- expect(Inspectors.new.all.inspect).to eq(%q{ <Inspectors
71
+ it 'formats a collection' do
72
+ expect(Inspectors.new.all.inspect).to eq(' <Inspectors
73
73
  [
74
74
  <Inspector
75
75
  id=1,
@@ -80,6 +80,6 @@ describe Cistern::Formatter::Formatador do
80
80
  name="4"
81
81
  >
82
82
  ]
83
- >})
83
+ >')
84
84
  end
85
85
  end
data/spec/hash_spec.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Cistern::Hash" do
4
- describe "#slice" do
3
+ describe 'Cistern::Hash' do
4
+ describe '#slice' do
5
5
  let(:input) do
6
- { one: "one", two: "two", three: "three" }
6
+ { one: 'one', two: 'two', three: 'three' }
7
7
  end
8
8
 
9
- it "returns a new hash with only the specified keys" do
10
- expect(Cistern::Hash.slice(input, :one, :two)).to eq({ one: "one", two: "two" })
9
+ it 'returns a new hash with only the specified keys' do
10
+ expect(Cistern::Hash.slice(input, :one, :two)).to eq(one: 'one', two: 'two')
11
11
  end
12
12
 
13
13
  it "skips keys that aren't in the original hash" do
@@ -15,13 +15,13 @@ describe "Cistern::Hash" do
15
15
  end
16
16
  end
17
17
 
18
- describe "#except" do
18
+ describe '#except' do
19
19
  let(:input) do
20
- { one: "one", two: "two", three: "three" }
20
+ { one: 'one', two: 'two', three: 'three' }
21
21
  end
22
22
 
23
- it "returns a new hash without the specified keys" do
24
- expect(Cistern::Hash.except(input, :one, :two)).to eq({three: "three"})
23
+ it 'returns a new hash without the specified keys' do
24
+ expect(Cistern::Hash.except(input, :one, :two)).to eq(three: 'three')
25
25
  end
26
26
 
27
27
  it "skips keys that aren't in the original hash" do
@@ -29,22 +29,22 @@ describe "Cistern::Hash" do
29
29
  end
30
30
  end
31
31
 
32
- describe "#stringify_keys" do
32
+ describe '#stringify_keys' do
33
33
  let(:input) do
34
- { one: "one", two: "two" }
34
+ { one: 'one', two: 'two' }
35
35
  end
36
36
 
37
- it "returns a new hash with stringed keys" do
38
- expect(Cistern::Hash.stringify_keys(input)).to eq({ "one" => "one", "two" => "two" })
37
+ it 'returns a new hash with stringed keys' do
38
+ expect(Cistern::Hash.stringify_keys(input)).to eq('one' => 'one', 'two' => 'two')
39
39
  end
40
40
 
41
- context "with nested hashes or arrays" do
41
+ context 'with nested hashes or arrays' do
42
42
  let(:input) do
43
- { hash: { one: "one" }, array: [{ two: "two" }] }
43
+ { hash: { one: 'one' }, array: [{ two: 'two' }] }
44
44
  end
45
45
 
46
- it "stringifies all of the keys" do
47
- expect(Cistern::Hash.stringify_keys(input)).to eq({ "hash" => { "one" => "one" }, "array" => [{ "two" => "two" }]})
46
+ it 'stringifies all of the keys' do
47
+ expect(Cistern::Hash.stringify_keys(input)).to eq('hash' => { 'one' => 'one' }, 'array' => [{ 'two' => 'two' }])
48
48
  end
49
49
  end
50
50
  end
@@ -19,50 +19,49 @@ describe 'mock data' do
19
19
  end
20
20
  end
21
21
 
22
- shared_examples "mock_data#backend" do |backend, options|
23
- it "should store mock data" do
22
+ shared_examples 'mock_data#backend' do |backend, options|
23
+ it 'should store mock data' do
24
24
  Sample.mock!
25
25
  Sample::Mock.store_in(backend, options)
26
26
  Sample.reset!
27
27
 
28
28
  p = Sample.new
29
- p.diagnosis("sick")
30
- expect(p.data[:diagnosis]).to eq(["sick"])
29
+ p.diagnosis('sick')
30
+ expect(p.data[:diagnosis]).to eq(['sick'])
31
31
 
32
32
  p.reset!
33
33
 
34
34
  expect(p.data[:diagnosis]).to eq([])
35
35
 
36
- p.treat("healthy")
37
- expect(p.data[:treatments]).to eq(["healthy"])
36
+ p.treat('healthy')
37
+ expect(p.data[:treatments]).to eq(['healthy'])
38
38
 
39
39
  Sample.reset!
40
40
 
41
41
  expect(p.data[:treatments]).to eq([])
42
42
  end
43
-
44
43
  end
45
44
 
46
- context "with a storage backend" do
47
- describe "Cistern::Data::Hash" do
48
- include_examples "mock_data#backend", :hash
45
+ context 'with a storage backend' do
46
+ describe 'Cistern::Data::Hash' do
47
+ include_examples 'mock_data#backend', :hash
49
48
  end
50
49
 
51
- describe "Cistern::Data::Redis" do
52
- include_examples "mock_data#backend", :redis
50
+ describe 'Cistern::Data::Redis' do
51
+ include_examples 'mock_data#backend', :redis
53
52
 
54
- context "with an explicit client" do
55
- before(:each) {
56
- @other = Redis::Namespace.new("other_cistern", Redis.new)
57
- @other.set("x", "y")
58
- }
53
+ context 'with an explicit client' do
54
+ before(:each) do
55
+ @other = Redis::Namespace.new('other_cistern', Redis.new)
56
+ @other.set('x', 'y')
57
+ end
59
58
 
60
- include_examples "mock_data#backend", :redis, client: Redis::Namespace.new("cistern", Redis.new)
59
+ include_examples 'mock_data#backend', :redis, client: Redis::Namespace.new('cistern', Redis.new)
61
60
 
62
- after(:each) {
63
- expect(@other.get("x")).to eq("y")
64
- @other.del("x")
65
- }
61
+ after(:each) do
62
+ expect(@other.get('x')).to eq('y')
63
+ @other.del('x')
64
+ end
66
65
  end
67
66
  end
68
67
  end