axiom-do-adapter 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -0
  3. data/.ruby-gemset +1 -0
  4. data/.travis.yml +17 -23
  5. data/CONTRIBUTING.md +1 -2
  6. data/Gemfile +10 -5
  7. data/Gemfile.devtools +39 -27
  8. data/README.md +3 -6
  9. data/axiom-do-adapter.gemspec +5 -7
  10. data/config/devtools.yml +2 -0
  11. data/config/reek.yml +2 -7
  12. data/config/rubocop.yml +59 -0
  13. data/lib/axiom/adapter/data_objects/statement.rb +4 -7
  14. data/lib/axiom/adapter/data_objects/version.rb +1 -1
  15. data/lib/axiom/relation/gateway.rb +3 -3
  16. data/spec/shared/binary_relation_method_behaviour.rb +11 -11
  17. data/spec/shared/unary_relation_method_behaviour.rb +4 -4
  18. data/spec/spec_helper.rb +13 -18
  19. data/spec/support/config_alias.rb +2 -0
  20. data/spec/unit/axiom/adapter/data_objects/class_methods/new_spec.rb +1 -1
  21. data/spec/unit/axiom/adapter/data_objects/read_spec.rb +14 -18
  22. data/spec/unit/axiom/adapter/data_objects/statement/class_methods/new_spec.rb +3 -3
  23. data/spec/unit/axiom/adapter/data_objects/statement/each_spec.rb +23 -24
  24. data/spec/unit/axiom/adapter/data_objects/statement/to_s_spec.rb +9 -9
  25. data/spec/unit/axiom/relation/gateway/class_methods/new_spec.rb +2 -2
  26. data/spec/unit/axiom/relation/gateway/difference_spec.rb +3 -3
  27. data/spec/unit/axiom/relation/gateway/drop_spec.rb +6 -6
  28. data/spec/unit/axiom/relation/gateway/each_spec.rb +19 -23
  29. data/spec/unit/axiom/relation/gateway/extend_spec.rb +10 -12
  30. data/spec/unit/axiom/relation/gateway/intersect_spec.rb +3 -3
  31. data/spec/unit/axiom/relation/gateway/join_spec.rb +11 -11
  32. data/spec/unit/axiom/relation/gateway/materialize_spec.rb +9 -9
  33. data/spec/unit/axiom/relation/gateway/optimize_spec.rb +4 -4
  34. data/spec/unit/axiom/relation/gateway/product_spec.rb +3 -3
  35. data/spec/unit/axiom/relation/gateway/project_spec.rb +6 -6
  36. data/spec/unit/axiom/relation/gateway/remove_spec.rb +6 -6
  37. data/spec/unit/axiom/relation/gateway/rename_spec.rb +6 -6
  38. data/spec/unit/axiom/relation/gateway/respond_to_spec.rb +2 -2
  39. data/spec/unit/axiom/relation/gateway/restrict_spec.rb +10 -12
  40. data/spec/unit/axiom/relation/gateway/reverse_spec.rb +6 -6
  41. data/spec/unit/axiom/relation/gateway/sort_by_spec.rb +10 -12
  42. data/spec/unit/axiom/relation/gateway/summarize_spec.rb +48 -54
  43. data/spec/unit/axiom/relation/gateway/take_spec.rb +6 -6
  44. data/spec/unit/axiom/relation/gateway/union_spec.rb +3 -3
  45. metadata +23 -44
  46. data/.rvmrc +0 -1
  47. data/spec/support/example_group_methods.rb +0 -7
  48. data/spec/support/ice_nine_config.rb +0 -6
@@ -1,21 +1,21 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  shared_examples_for 'a unary relation method' do
4
- let(:gateway) { mock('New Gateway') }
4
+ let(:gateway) { double('New Gateway') }
5
5
 
6
6
  before do
7
- described_class.stub!(:new).and_return(gateway)
7
+ allow(described_class).to receive(:new).and_return(gateway)
8
8
  end
9
9
 
10
10
  it { should equal(gateway) }
11
11
 
12
12
  it 'tests the response is a relation' do
13
- response.should_receive(:kind_of?).with(Relation)
13
+ expect(response).to receive(:kind_of?).with(Relation)
14
14
  subject
15
15
  end
16
16
 
17
17
  it 'initializes the new gateway with the adapter and response' do
18
- described_class.should_receive(:new).with(adapter, response)
18
+ expect(described_class).to receive(:new).with(adapter, response)
19
19
  subject
20
20
  end
21
21
  end
@@ -1,38 +1,33 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'backports'
4
- require 'backports/basic_object' unless defined?(::BasicObject)
5
- require 'devtools/spec_helper'
6
- require 'ice_nine'
7
-
8
3
  if ENV['COVERAGE'] == 'true'
9
4
  require 'simplecov'
10
5
  require 'coveralls'
11
6
 
12
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
13
- SimpleCov::Formatter::HTMLFormatter,
14
- Coveralls::SimpleCov::Formatter
15
- ]
7
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ SimpleCov::Formatter::HTMLFormatter,
8
+ Coveralls::SimpleCov::Formatter
9
+ ]
16
10
 
17
11
  SimpleCov.start do
18
- command_name 'spec:unit'
19
- add_filter 'config'
20
- add_filter 'spec'
12
+ command_name 'spec:unit'
13
+
14
+ add_filter 'config'
15
+ add_filter 'spec'
16
+ add_filter 'vendor'
17
+
21
18
  minimum_coverage 100
22
19
  end
23
20
  end
24
21
 
22
+ require 'devtools/spec_helper'
25
23
  require 'axiom-do-adapter'
26
24
 
27
25
  include Axiom
28
26
 
29
- # require spec support files and shared behavior
30
- Dir[File.expand_path('../{support,shared}/**/*.rb', __FILE__)].each do |file|
31
- require file
32
- end
33
-
34
27
  RSpec.configure do |config|
35
- config.extend Spec::ExampleGroupMethods
28
+ config.expect_with :rspec do |expect_with|
29
+ expect_with.syntax = :expect
30
+ end
36
31
 
37
32
  # Record the original Attribute descendants
38
33
  config.before do
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'rbconfig'
2
4
 
3
5
  ::Config = RbConfig unless defined?(::Config)
@@ -6,7 +6,7 @@ require 'axiom/adapter/data_objects'
6
6
  describe Adapter::DataObjects, '.new' do
7
7
  subject { object.new(uri) }
8
8
 
9
- let(:uri) { stub }
9
+ let(:uri) { double }
10
10
  let(:object) { described_class }
11
11
 
12
12
  it { should be_instance_of(described_class) }
@@ -4,56 +4,52 @@ require 'spec_helper'
4
4
  require 'axiom/adapter/data_objects'
5
5
 
6
6
  describe Adapter::DataObjects, '#read' do
7
- let(:uri) { stub }
7
+ let(:uri) { double }
8
8
  let(:object) { described_class.new(uri) }
9
- let(:relation) { mock('Relation') }
10
- let(:statement) { mock('Statement') }
11
- let(:rows) { [ [ 1 ], [ 2 ], [ 3 ] ] }
9
+ let(:relation) { double('Relation') }
10
+ let(:statement) { double('Statement') }
11
+ let(:rows) { [[1], [2], [3]] }
12
12
  let(:yields) { [] }
13
13
 
14
14
  before do
15
- expectation = statement.stub(:each)
16
- rows.each { |row| expectation.and_yield(row) }
17
-
18
- described_class::Statement.stub!(:new).and_return(statement)
15
+ allow(statement).to receive(:each, &rows.method(:each))
16
+ allow(described_class::Statement).to receive(:new).and_return(statement)
19
17
  end
20
18
 
21
19
  context 'with a block' do
22
20
  subject { object.read(relation) { |row| yields << row } }
23
21
 
24
- let(:connection) { mock('Connection', :close => nil) }
22
+ let(:connection) { double('Connection', close: nil) }
25
23
 
26
24
  before do
27
- DataObjects::Connection.stub!(:new).and_return(connection)
25
+ allow(DataObjects::Connection).to receive(:new).and_return(connection)
28
26
  end
29
27
 
30
28
  it_should_behave_like 'a command method'
31
29
 
32
30
  it 'opens a connection' do
33
- DataObjects::Connection.should_receive(:new).with(uri).and_return(connection)
31
+ expect(DataObjects::Connection).to receive(:new).with(uri).and_return(connection)
34
32
  subject
35
33
  end
36
34
 
37
35
  it 'closes a connection' do
38
- connection.should_receive(:close).with(no_args)
36
+ expect(connection).to receive(:close).with(no_args)
39
37
  subject
40
38
  end
41
39
 
42
40
  it 'does not close a connection if the constructor throws an exception' do
43
41
  mock_exception = Class.new(Exception)
44
- DataObjects::Connection.should_receive(:new).and_raise(mock_exception)
45
- connection.should_not_receive(:close)
42
+ expect(DataObjects::Connection).to receive(:new).and_raise(mock_exception)
43
+ expect(connection).not_to receive(:close)
46
44
  expect { subject }.to raise_error(mock_exception)
47
45
  end
48
46
 
49
47
  it 'yields each row' do
50
- expect { subject }.to change { yields.dup }.
51
- from([]).
52
- to(rows)
48
+ expect { subject }.to change { yields.dup }.from([]).to(rows)
53
49
  end
54
50
 
55
51
  it 'initializes a statement' do
56
- described_class::Statement.should_receive(:new).with(connection, relation).and_return(statement)
52
+ expect(described_class::Statement).to receive(:new).with(connection, relation).and_return(statement)
57
53
  subject
58
54
  end
59
55
  end
@@ -4,8 +4,8 @@ require 'spec_helper'
4
4
  require 'axiom/adapter/data_objects/statement'
5
5
 
6
6
  describe Adapter::DataObjects::Statement, '.new' do
7
- let(:connection) { stub }
8
- let(:relation) { stub }
7
+ let(:connection) { double }
8
+ let(:relation) { double }
9
9
  let(:object) { described_class }
10
10
 
11
11
  context 'without a visitor' do
@@ -19,7 +19,7 @@ describe Adapter::DataObjects::Statement, '.new' do
19
19
  context 'with a visitor' do
20
20
  subject { object.new(connection, relation, visitor) }
21
21
 
22
- let(:visitor) { stub }
22
+ let(:visitor) { double }
23
23
 
24
24
  it { should be_instance_of(described_class) }
25
25
 
@@ -4,20 +4,21 @@ require 'spec_helper'
4
4
  require 'axiom/adapter/data_objects/statement'
5
5
 
6
6
  describe Adapter::DataObjects::Statement, '#each' do
7
- let(:reader) { mock('Reader', :next! => false).as_null_object }
8
- let(:command) { mock('Command', :execute_reader => reader).as_null_object }
9
- let(:connection) { mock('Connection', :create_command => command) }
10
- let(:attribute) { stub }
11
- let(:primitive) { stub }
12
- let(:relation) { mock('Relation', :header => [ attribute ]) }
13
- let(:generator) { mock('Generator').as_null_object }
14
- let(:rows) { [ stub, stub ] }
15
- let(:object) { described_class.new(connection, relation, generator) }
16
- let(:yields) { [] }
7
+ let(:reader) { double('Reader', :next! => false).as_null_object }
8
+ let(:command) { double('Command', execute_reader: reader).as_null_object }
9
+ let(:connection) { double('Connection', create_command: command) }
10
+ let(:attribute) { double }
11
+ let(:primitive) { double }
12
+ let(:relation) { double('Relation', header: [attribute]) }
13
+ let(:generator) { double('Generator').as_null_object }
14
+ let(:rows) { [double, double] }
15
+ let(:object) { described_class.new(connection, relation, generator) }
16
+ let(:yields) { [] }
17
17
 
18
18
  before do
19
- command.stub!(:dup => command, :freeze => command)
20
- attribute.stub_chain(:class, :primitive).and_return(primitive)
19
+ allow(command).to receive(:dup).and_return(command)
20
+ allow(command).to receive(:freeze).and_return(command)
21
+ attribute.stub_chain(:type, :primitive).and_return(primitive)
21
22
  end
22
23
 
23
24
  context 'with no block' do
@@ -26,7 +27,7 @@ describe Adapter::DataObjects::Statement, '#each' do
26
27
  it { should be_instance_of(to_enum.class) }
27
28
 
28
29
  it 'yields the expected attributes' do
29
- subject.to_a.should eql(object.to_a)
30
+ expect(subject.to_a).to eql(object.to_a)
30
31
  end
31
32
  end
32
33
 
@@ -34,30 +35,28 @@ describe Adapter::DataObjects::Statement, '#each' do
34
35
  subject { object.each { |row| yields << row } }
35
36
 
36
37
  before do
37
- connection.should_receive(:create_command).with(object.to_s)
38
+ expect(connection).to receive(:create_command).with(object.to_s)
38
39
 
39
- command.should_receive(:set_types).with([ primitive ]).ordered
40
- command.should_receive(:execute_reader).with(no_args).ordered
40
+ expect(command).to receive(:set_types).with([primitive]).ordered
41
+ expect(command).to receive(:execute_reader).with(no_args).ordered
41
42
 
42
43
  rows.each do |values|
43
- reader.should_receive(:next!).with(no_args).ordered.and_return(true)
44
- reader.should_receive(:values).with(no_args).ordered.and_return(values)
44
+ expect(reader).to receive(:next!).with(no_args).ordered.and_return(true)
45
+ expect(reader).to receive(:values).with(no_args).ordered.and_return(values)
45
46
  end
46
47
 
47
- reader.should_receive(:next!).with(no_args).ordered.and_return(false)
48
- reader.should_receive(:close).with(no_args).ordered
48
+ expect(reader).to receive(:next!).with(no_args).ordered.and_return(false)
49
+ expect(reader).to receive(:close).with(no_args).ordered
49
50
  end
50
51
 
51
52
  before do
52
- relation.should_receive(:header)
53
+ expect(relation).to receive(:header)
53
54
  end
54
55
 
55
56
  it_should_behave_like 'a command method'
56
57
 
57
58
  it 'yields each row' do
58
- expect { subject }.to change { yields.dup }.
59
- from([]).
60
- to(rows)
59
+ expect { subject }.to change { yields.dup }.from([]).to(rows)
61
60
  end
62
61
  end
63
62
  end
@@ -6,17 +6,17 @@ require 'axiom/adapter/data_objects/statement'
6
6
  describe Adapter::DataObjects::Statement, '#to_s' do
7
7
  subject { object.to_s }
8
8
 
9
- let(:sql) { mock('SQL') }
10
- let(:connection) { stub }
11
- let(:relation) { mock('Relation') }
12
- let(:generator) { mock('Generator', :to_sql => sql) }
9
+ let(:sql) { double('SQL') }
10
+ let(:connection) { double }
11
+ let(:relation) { double('Relation') }
12
+ let(:generator) { double('Generator', to_sql: sql) }
13
13
 
14
14
  context 'without a visitor' do
15
15
  let(:visitor) { SQL::Generator::Relation } # default visitor
16
16
  let(:object) { described_class.new(connection, relation) }
17
17
 
18
18
  before do
19
- visitor.stub!(:visit).and_return(generator)
19
+ allow(visitor).to receive(:visit).and_return(generator)
20
20
  end
21
21
 
22
22
  it_should_behave_like 'an idempotent method'
@@ -26,17 +26,17 @@ describe Adapter::DataObjects::Statement, '#to_s' do
26
26
  it { should equal(sql) }
27
27
 
28
28
  it 'visits the relation' do
29
- visitor.should_receive(:visit).with(relation)
29
+ expect(visitor).to receive(:visit).with(relation)
30
30
  subject
31
31
  end
32
32
  end
33
33
 
34
34
  context 'with a visitor' do
35
- let(:visitor) { mock('Visitor', :visit => generator) }
35
+ let(:visitor) { double('Visitor', visit: generator) }
36
36
  let(:object) { described_class.new(connection, relation, visitor) }
37
37
 
38
38
  before do
39
- visitor.stub!(:visit).and_return(generator)
39
+ allow(visitor).to receive(:visit).and_return(generator)
40
40
  end
41
41
 
42
42
  it_should_behave_like 'an idempotent method'
@@ -46,7 +46,7 @@ describe Adapter::DataObjects::Statement, '#to_s' do
46
46
  it { should equal(sql) }
47
47
 
48
48
  it 'visits the relation' do
49
- visitor.should_receive(:visit).with(relation)
49
+ expect(visitor).to receive(:visit).with(relation)
50
50
  subject
51
51
  end
52
52
  end
@@ -6,8 +6,8 @@ require 'axiom/relation/gateway'
6
6
  describe Relation::Gateway, '.new' do
7
7
  subject { object.new(adapter, relation) }
8
8
 
9
- let(:adapter) { stub }
10
- let(:relation) { stub }
9
+ let(:adapter) { double }
10
+ let(:relation) { double }
11
11
  let(:object) { described_class }
12
12
 
13
13
  it { should be_instance_of(described_class) }
@@ -6,12 +6,12 @@ require 'axiom/relation/gateway'
6
6
  describe Relation::Gateway, '#difference' do
7
7
  subject { object.difference(other) }
8
8
 
9
- let(:adapter) { mock('Adapter') }
10
- let(:relation) { mock('Relation') }
9
+ let(:adapter) { double('Adapter') }
10
+ let(:relation) { double('Relation') }
11
11
  let(:object) { described_class.new(adapter, relation) }
12
12
  let(:operation) { :difference }
13
13
  let(:factory) { Algebra::Difference }
14
- let(:binary_relation) { mock(factory) }
14
+ let(:binary_relation) { double(factory) }
15
15
 
16
16
  it_should_behave_like 'a binary relation method'
17
17
  end
@@ -6,16 +6,16 @@ require 'axiom/relation/gateway'
6
6
  describe Relation::Gateway, '#drop' do
7
7
  subject { object.drop(args) }
8
8
 
9
- let(:adapter) { mock('Adapter') }
10
- let(:relation) { mock('Relation', :drop => response) }
11
- let(:response) { mock('New Relation', :kind_of? => true) }
12
- let!(:object) { described_class.new(adapter, relation) }
13
- let(:args) { stub }
9
+ let(:adapter) { double('Adapter') }
10
+ let(:relation) { double('Relation', drop: response) }
11
+ let(:response) { double('New Relation', :kind_of? => true) }
12
+ let!(:object) { described_class.new(adapter, relation) }
13
+ let(:args) { double }
14
14
 
15
15
  it_should_behave_like 'a unary relation method'
16
16
 
17
17
  it 'forwards the arguments to relation#drop' do
18
- relation.should_receive(:drop).with(args)
18
+ expect(relation).to receive(:drop).with(args)
19
19
  subject
20
20
  end
21
21
  end
@@ -6,50 +6,48 @@ require 'axiom/relation/gateway'
6
6
  describe Relation::Gateway, '#each' do
7
7
  subject { object.each { |tuple| yields << tuple } }
8
8
 
9
- let(:header) { mock('Header') }
10
- let(:reader) { mock('Reader') }
11
- let(:tuple) { mock('Tuple') }
12
- let(:adapter) { mock('Adapter') }
13
- let(:relation) { mock('Relation') }
9
+ let(:header) { double('Header') }
10
+ let(:reader) { double('Reader') }
11
+ let(:tuple) { double('Tuple') }
12
+ let(:adapter) { double('Adapter') }
13
+ let(:relation) { double('Relation') }
14
14
  let!(:object) { described_class.new(adapter, relation) }
15
15
  let(:yields) { [] }
16
16
 
17
17
  context 'with an unmaterialized relation' do
18
- let(:wrapper) { stub }
18
+ let(:wrapper) { double }
19
19
 
20
20
  before do
21
- adapter.stub!(:read).and_return(reader)
21
+ allow(adapter).to receive(:read).and_return(reader)
22
22
 
23
- relation.stub!(:header).and_return(header)
24
- relation.stub!(:materialized?).and_return(false)
25
- relation.stub!(:each).and_return(relation)
23
+ allow(relation).to receive(:header).and_return(header)
24
+ allow(relation).to receive(:materialized?).and_return(false)
25
+ allow(relation).to receive(:each).and_return(relation)
26
26
 
27
- wrapper.stub!(:each).and_yield(tuple)
28
- Relation.stub!(:new).and_return(wrapper)
27
+ allow(wrapper).to receive(:each).and_yield(tuple)
28
+ allow(Relation).to receive(:new).and_return(wrapper)
29
29
  end
30
30
 
31
31
  it_should_behave_like 'an #each method'
32
32
 
33
33
  it 'yields each tuple' do
34
- expect { subject }.to change { yields.dup }.
35
- from([]).
36
- to([ tuple ])
34
+ expect { subject }.to change { yields.dup }.from([]).to([tuple])
37
35
  end
38
36
 
39
37
  it 'passes in the relation to the adapter reader' do
40
- adapter.should_receive(:read).with(relation)
38
+ expect(adapter).to receive(:read).with(relation)
41
39
  subject
42
40
  end
43
41
 
44
42
  it 'passes in the relation header and reader to the wrapper constructor' do
45
- Relation.should_receive(:new).with(header, reader)
43
+ expect(Relation).to receive(:new).with(header, reader)
46
44
  subject
47
45
  end
48
46
  end
49
47
 
50
48
  context 'with a materialized relation' do
51
49
  before do
52
- relation.stub!(:materialized?).and_return(true)
50
+ allow(relation).to receive(:materialized?).and_return(true)
53
51
 
54
52
  tuple = self.tuple
55
53
 
@@ -68,18 +66,16 @@ describe Relation::Gateway, '#each' do
68
66
  it_should_behave_like 'an #each method'
69
67
 
70
68
  it 'yields each tuple' do
71
- expect { subject }.to change { yields.dup }.
72
- from([]).
73
- to([ tuple ])
69
+ expect { subject }.to change { yields.dup }.from([]).to([tuple])
74
70
  end
75
71
 
76
72
  it 'does not create a reader' do
77
- adapter.should_not_receive(:read)
73
+ expect(adapter).not_to receive(:read)
78
74
  subject
79
75
  end
80
76
 
81
77
  it 'does not create a wrapper' do
82
- Relation.should_not_receive(:new)
78
+ expect(Relation).not_to receive(:new)
83
79
  subject
84
80
  end
85
81
  end