nql 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -18
- data/Gemfile +4 -4
- data/LICENSE +21 -21
- data/README.md +54 -54
- data/Rakefile +2 -2
- data/lib/nql.rb +25 -25
- data/lib/nql/grammar.rb +760 -760
- data/lib/nql/grammar.treetop +108 -108
- data/lib/nql/invalid_expression_error.rb +6 -6
- data/lib/nql/version.rb +3 -3
- data/nql.gemspec +25 -25
- data/spec/comparison_parser_spec.rb +147 -147
- data/spec/coordination_parser_spec.rb +42 -42
- data/spec/migrations/20121108154439_create_countries.rb +9 -9
- data/spec/migrations/20121108154508_create_cities.rb +10 -10
- data/spec/models/city.rb +2 -2
- data/spec/models/country.rb +2 -2
- data/spec/ransack_spec.rb +134 -134
- data/spec/spec_helper.rb +44 -44
- data/spec/sql_spec.rb +116 -116
- metadata +45 -15
@@ -1,43 +1,43 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe NQL::SyntaxParser, '-> Coordination' do
|
4
|
-
|
5
|
-
let(:parser) { NQL::SyntaxParser.new }
|
6
|
-
|
7
|
-
it 'And' do
|
8
|
-
tree = parser.parse('var1 = value1 & var2 = value2')
|
9
|
-
|
10
|
-
tree.left.text_value.strip.should eq 'var1 = value1'
|
11
|
-
tree.coordinator.text_value.should eq '&'
|
12
|
-
tree.right.text_value.strip.should eq 'var2 = value2'
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'Or' do
|
16
|
-
tree = parser.parse('var1 = value1 | var2 = value2')
|
17
|
-
|
18
|
-
tree.left.text_value.strip.should eq 'var1 = value1'
|
19
|
-
tree.coordinator.text_value.should eq '|'
|
20
|
-
tree.right.text_value.strip.should eq 'var2 = value2'
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'And then Or' do
|
24
|
-
tree = parser.parse('var1 = value1 & var2 = value2 | var3 = value3')
|
25
|
-
|
26
|
-
tree.left.text_value.strip.should eq 'var1 = value1'
|
27
|
-
tree.coordinator.text_value.should eq '&'
|
28
|
-
tree.right.left.text_value.strip.should eq 'var2 = value2'
|
29
|
-
tree.right.coordinator.text_value.strip.should eq '|'
|
30
|
-
tree.right.right.text_value.strip.should eq 'var3 = value3'
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'With parentheses' do
|
34
|
-
tree = parser.parse('(var1 = value1 & var2 = value2) | var3 = value3')
|
35
|
-
|
36
|
-
tree.left.expression.left.text_value.strip.should eq 'var1 = value1'
|
37
|
-
tree.left.expression.coordinator.text_value.should eq '&'
|
38
|
-
tree.left.expression.right.text_value.strip.should eq 'var2 = value2'
|
39
|
-
tree.coordinator.text_value.strip.should eq '|'
|
40
|
-
tree.right.text_value.strip.should eq 'var3 = value3'
|
41
|
-
end
|
42
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NQL::SyntaxParser, '-> Coordination' do
|
4
|
+
|
5
|
+
let(:parser) { NQL::SyntaxParser.new }
|
6
|
+
|
7
|
+
it 'And' do
|
8
|
+
tree = parser.parse('var1 = value1 & var2 = value2')
|
9
|
+
|
10
|
+
tree.left.text_value.strip.should eq 'var1 = value1'
|
11
|
+
tree.coordinator.text_value.should eq '&'
|
12
|
+
tree.right.text_value.strip.should eq 'var2 = value2'
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'Or' do
|
16
|
+
tree = parser.parse('var1 = value1 | var2 = value2')
|
17
|
+
|
18
|
+
tree.left.text_value.strip.should eq 'var1 = value1'
|
19
|
+
tree.coordinator.text_value.should eq '|'
|
20
|
+
tree.right.text_value.strip.should eq 'var2 = value2'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'And then Or' do
|
24
|
+
tree = parser.parse('var1 = value1 & var2 = value2 | var3 = value3')
|
25
|
+
|
26
|
+
tree.left.text_value.strip.should eq 'var1 = value1'
|
27
|
+
tree.coordinator.text_value.should eq '&'
|
28
|
+
tree.right.left.text_value.strip.should eq 'var2 = value2'
|
29
|
+
tree.right.coordinator.text_value.strip.should eq '|'
|
30
|
+
tree.right.right.text_value.strip.should eq 'var3 = value3'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'With parentheses' do
|
34
|
+
tree = parser.parse('(var1 = value1 & var2 = value2) | var3 = value3')
|
35
|
+
|
36
|
+
tree.left.expression.left.text_value.strip.should eq 'var1 = value1'
|
37
|
+
tree.left.expression.coordinator.text_value.should eq '&'
|
38
|
+
tree.left.expression.right.text_value.strip.should eq 'var2 = value2'
|
39
|
+
tree.coordinator.text_value.strip.should eq '|'
|
40
|
+
tree.right.text_value.strip.should eq 'var3 = value3'
|
41
|
+
end
|
42
|
+
|
43
43
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
class CreateCountries < ActiveRecord::Migration
|
2
|
-
def change
|
3
|
-
create_table :countries do |t|
|
4
|
-
t.string :name, null: false
|
5
|
-
|
6
|
-
t.timestamps
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
1
|
+
class CreateCountries < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :countries do |t|
|
4
|
+
t.string :name, null: false
|
5
|
+
|
6
|
+
t.timestamps
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
class CreateCities < ActiveRecord::Migration
|
2
|
-
def change
|
3
|
-
create_table :cities do |t|
|
4
|
-
t.string :name, null: false
|
5
|
-
t.references :country
|
6
|
-
|
7
|
-
t.timestamps
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
1
|
+
class CreateCities < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :cities do |t|
|
4
|
+
t.string :name, null: false
|
5
|
+
t.references :country
|
6
|
+
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/spec/models/city.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
class City < ActiveRecord::Base
|
2
|
-
belongs_to :country
|
1
|
+
class City < ActiveRecord::Base
|
2
|
+
belongs_to :country
|
3
3
|
end
|
data/spec/models/country.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
class Country < ActiveRecord::Base
|
2
|
-
has_many :cities, dependent: :destroy
|
1
|
+
class Country < ActiveRecord::Base
|
2
|
+
has_many :cities, dependent: :destroy
|
3
3
|
end
|
data/spec/ransack_spec.rb
CHANGED
@@ -1,135 +1,135 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Ransack Query' do
|
4
|
-
|
5
|
-
let(:parser) { NQL::SyntaxParser.new }
|
6
|
-
|
7
|
-
context 'Single comparisons' do
|
8
|
-
|
9
|
-
it 'Equals' do
|
10
|
-
q = parser.parse('id = 1234').to_ransack
|
11
|
-
|
12
|
-
q[:c][0].should have_attribute 'id'
|
13
|
-
q[:c][0].should have_predicate 'eq'
|
14
|
-
q[:c][0].should have_value '1234'
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'Not equals' do
|
18
|
-
q = parser.parse('id != 1234').to_ransack
|
19
|
-
|
20
|
-
q[:c][0].should have_attribute 'id'
|
21
|
-
q[:c][0].should have_predicate 'not_eq'
|
22
|
-
q[:c][0].should have_value '1234'
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'Greater than' do
|
26
|
-
q = parser.parse('id > 1234').to_ransack
|
27
|
-
|
28
|
-
q[:c][0].should have_attribute 'id'
|
29
|
-
q[:c][0].should have_predicate 'gt'
|
30
|
-
q[:c][0].should have_value '1234'
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'Greater or equals than' do
|
34
|
-
q = parser.parse('id >= 1234').to_ransack
|
35
|
-
|
36
|
-
q[:c][0].should have_attribute 'id'
|
37
|
-
q[:c][0].should have_predicate 'gteq'
|
38
|
-
q[:c][0].should have_value '1234'
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'Less than' do
|
42
|
-
q = parser.parse('id < 1234').to_ransack
|
43
|
-
|
44
|
-
q[:c][0].should have_attribute 'id'
|
45
|
-
q[:c][0].should have_predicate 'lt'
|
46
|
-
q[:c][0].should have_value '1234'
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'Less or equals than' do
|
50
|
-
q = parser.parse('id <= 1234').to_ransack
|
51
|
-
|
52
|
-
q[:c][0].should have_attribute 'id'
|
53
|
-
q[:c][0].should have_predicate 'lteq'
|
54
|
-
q[:c][0].should have_value '1234'
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'Contains' do
|
58
|
-
q = parser.parse('id : 1234').to_ransack
|
59
|
-
|
60
|
-
q[:c][0].should have_attribute 'id'
|
61
|
-
q[:c][0].should have_predicate 'cont'
|
62
|
-
q[:c][0].should have_value '1234'
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'Model references' do
|
66
|
-
q = parser.parse('models.id = 1234').to_ransack
|
67
|
-
|
68
|
-
q[:c][0].should have_attribute 'models_id'
|
69
|
-
q[:c][0].should have_predicate 'eq'
|
70
|
-
q[:c][0].should have_value '1234'
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
context 'Coordinated comparisons' do
|
76
|
-
|
77
|
-
it 'And' do
|
78
|
-
q = parser.parse('id > 1234 & name = abcd').to_ransack
|
79
|
-
|
80
|
-
q[:g][0][:m].should eq 'and'
|
81
|
-
q[:g][0][:c][0].should have_attribute 'id'
|
82
|
-
q[:g][0][:c][0].should have_predicate 'gt'
|
83
|
-
q[:g][0][:c][0].should have_value '1234'
|
84
|
-
q[:g][0][:c][1].should have_attribute 'name'
|
85
|
-
q[:g][0][:c][1].should have_predicate 'eq'
|
86
|
-
q[:g][0][:c][1].should have_value 'abcd'
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'Or' do
|
90
|
-
q = parser.parse('id < 1234 | name : abcd').to_ransack
|
91
|
-
|
92
|
-
q[:g][0][:m].should eq 'or'
|
93
|
-
q[:g][0][:c][0].should have_attribute 'id'
|
94
|
-
q[:g][0][:c][0].should have_predicate 'lt'
|
95
|
-
q[:g][0][:c][0].should have_value '1234'
|
96
|
-
q[:g][0][:c][1].should have_attribute 'name'
|
97
|
-
q[:g][0][:c][1].should have_predicate 'cont'
|
98
|
-
q[:g][0][:c][1].should have_value 'abcd'
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'And then Or' do
|
102
|
-
q = parser.parse('id > 1234 & name = abcd | name : efgh').to_ransack
|
103
|
-
|
104
|
-
q[:g][0][:m].should eq 'and'
|
105
|
-
q[:g][0][:c][0].should have_attribute 'id'
|
106
|
-
q[:g][0][:c][0].should have_predicate 'gt'
|
107
|
-
q[:g][0][:c][0].should have_value '1234'
|
108
|
-
q[:g][0][:g][0][:m].should eq 'or'
|
109
|
-
q[:g][0][:g][0][:c][0].should have_attribute 'name'
|
110
|
-
q[:g][0][:g][0][:c][0].should have_predicate 'eq'
|
111
|
-
q[:g][0][:g][0][:c][0].should have_value 'abcd'
|
112
|
-
q[:g][0][:g][0][:c][1].should have_attribute 'name'
|
113
|
-
q[:g][0][:g][0][:c][1].should have_predicate 'cont'
|
114
|
-
q[:g][0][:g][0][:c][1].should have_value 'efgh'
|
115
|
-
end
|
116
|
-
|
117
|
-
it 'With parentheses' do
|
118
|
-
q = parser.parse('(id > 1234 & name = abcd) | name : efgh').to_ransack
|
119
|
-
|
120
|
-
q[:g][0][:g][0][:m].should eq 'and'
|
121
|
-
q[:g][0][:g][0][:c][0].should have_attribute 'id'
|
122
|
-
q[:g][0][:g][0][:c][0].should have_predicate 'gt'
|
123
|
-
q[:g][0][:g][0][:c][0].should have_value '1234'
|
124
|
-
q[:g][0][:g][0][:c][1].should have_attribute 'name'
|
125
|
-
q[:g][0][:g][0][:c][1].should have_predicate 'eq'
|
126
|
-
q[:g][0][:g][0][:c][1].should have_value 'abcd'
|
127
|
-
q[:g][0][:m].should eq 'or'
|
128
|
-
q[:g][0][:c][0].should have_attribute 'name'
|
129
|
-
q[:g][0][:c][0].should have_predicate 'cont'
|
130
|
-
q[:g][0][:c][0].should have_value 'efgh'
|
131
|
-
end
|
132
|
-
|
133
|
-
end
|
134
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Ransack Query' do
|
4
|
+
|
5
|
+
let(:parser) { NQL::SyntaxParser.new }
|
6
|
+
|
7
|
+
context 'Single comparisons' do
|
8
|
+
|
9
|
+
it 'Equals' do
|
10
|
+
q = parser.parse('id = 1234').to_ransack
|
11
|
+
|
12
|
+
q[:c][0].should have_attribute 'id'
|
13
|
+
q[:c][0].should have_predicate 'eq'
|
14
|
+
q[:c][0].should have_value '1234'
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'Not equals' do
|
18
|
+
q = parser.parse('id != 1234').to_ransack
|
19
|
+
|
20
|
+
q[:c][0].should have_attribute 'id'
|
21
|
+
q[:c][0].should have_predicate 'not_eq'
|
22
|
+
q[:c][0].should have_value '1234'
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'Greater than' do
|
26
|
+
q = parser.parse('id > 1234').to_ransack
|
27
|
+
|
28
|
+
q[:c][0].should have_attribute 'id'
|
29
|
+
q[:c][0].should have_predicate 'gt'
|
30
|
+
q[:c][0].should have_value '1234'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'Greater or equals than' do
|
34
|
+
q = parser.parse('id >= 1234').to_ransack
|
35
|
+
|
36
|
+
q[:c][0].should have_attribute 'id'
|
37
|
+
q[:c][0].should have_predicate 'gteq'
|
38
|
+
q[:c][0].should have_value '1234'
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'Less than' do
|
42
|
+
q = parser.parse('id < 1234').to_ransack
|
43
|
+
|
44
|
+
q[:c][0].should have_attribute 'id'
|
45
|
+
q[:c][0].should have_predicate 'lt'
|
46
|
+
q[:c][0].should have_value '1234'
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'Less or equals than' do
|
50
|
+
q = parser.parse('id <= 1234').to_ransack
|
51
|
+
|
52
|
+
q[:c][0].should have_attribute 'id'
|
53
|
+
q[:c][0].should have_predicate 'lteq'
|
54
|
+
q[:c][0].should have_value '1234'
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'Contains' do
|
58
|
+
q = parser.parse('id : 1234').to_ransack
|
59
|
+
|
60
|
+
q[:c][0].should have_attribute 'id'
|
61
|
+
q[:c][0].should have_predicate 'cont'
|
62
|
+
q[:c][0].should have_value '1234'
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'Model references' do
|
66
|
+
q = parser.parse('models.id = 1234').to_ransack
|
67
|
+
|
68
|
+
q[:c][0].should have_attribute 'models_id'
|
69
|
+
q[:c][0].should have_predicate 'eq'
|
70
|
+
q[:c][0].should have_value '1234'
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'Coordinated comparisons' do
|
76
|
+
|
77
|
+
it 'And' do
|
78
|
+
q = parser.parse('id > 1234 & name = abcd').to_ransack
|
79
|
+
|
80
|
+
q[:g][0][:m].should eq 'and'
|
81
|
+
q[:g][0][:c][0].should have_attribute 'id'
|
82
|
+
q[:g][0][:c][0].should have_predicate 'gt'
|
83
|
+
q[:g][0][:c][0].should have_value '1234'
|
84
|
+
q[:g][0][:c][1].should have_attribute 'name'
|
85
|
+
q[:g][0][:c][1].should have_predicate 'eq'
|
86
|
+
q[:g][0][:c][1].should have_value 'abcd'
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'Or' do
|
90
|
+
q = parser.parse('id < 1234 | name : abcd').to_ransack
|
91
|
+
|
92
|
+
q[:g][0][:m].should eq 'or'
|
93
|
+
q[:g][0][:c][0].should have_attribute 'id'
|
94
|
+
q[:g][0][:c][0].should have_predicate 'lt'
|
95
|
+
q[:g][0][:c][0].should have_value '1234'
|
96
|
+
q[:g][0][:c][1].should have_attribute 'name'
|
97
|
+
q[:g][0][:c][1].should have_predicate 'cont'
|
98
|
+
q[:g][0][:c][1].should have_value 'abcd'
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'And then Or' do
|
102
|
+
q = parser.parse('id > 1234 & name = abcd | name : efgh').to_ransack
|
103
|
+
|
104
|
+
q[:g][0][:m].should eq 'and'
|
105
|
+
q[:g][0][:c][0].should have_attribute 'id'
|
106
|
+
q[:g][0][:c][0].should have_predicate 'gt'
|
107
|
+
q[:g][0][:c][0].should have_value '1234'
|
108
|
+
q[:g][0][:g][0][:m].should eq 'or'
|
109
|
+
q[:g][0][:g][0][:c][0].should have_attribute 'name'
|
110
|
+
q[:g][0][:g][0][:c][0].should have_predicate 'eq'
|
111
|
+
q[:g][0][:g][0][:c][0].should have_value 'abcd'
|
112
|
+
q[:g][0][:g][0][:c][1].should have_attribute 'name'
|
113
|
+
q[:g][0][:g][0][:c][1].should have_predicate 'cont'
|
114
|
+
q[:g][0][:g][0][:c][1].should have_value 'efgh'
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'With parentheses' do
|
118
|
+
q = parser.parse('(id > 1234 & name = abcd) | name : efgh').to_ransack
|
119
|
+
|
120
|
+
q[:g][0][:g][0][:m].should eq 'and'
|
121
|
+
q[:g][0][:g][0][:c][0].should have_attribute 'id'
|
122
|
+
q[:g][0][:g][0][:c][0].should have_predicate 'gt'
|
123
|
+
q[:g][0][:g][0][:c][0].should have_value '1234'
|
124
|
+
q[:g][0][:g][0][:c][1].should have_attribute 'name'
|
125
|
+
q[:g][0][:g][0][:c][1].should have_predicate 'eq'
|
126
|
+
q[:g][0][:g][0][:c][1].should have_value 'abcd'
|
127
|
+
q[:g][0][:m].should eq 'or'
|
128
|
+
q[:g][0][:c][0].should have_attribute 'name'
|
129
|
+
q[:g][0][:c][0].should have_predicate 'cont'
|
130
|
+
q[:g][0][:c][0].should have_value 'efgh'
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
135
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,45 +1,45 @@
|
|
1
|
-
require 'nql'
|
2
|
-
|
3
|
-
Dir["#{File.dirname(__FILE__)}/models/**/*.rb"].each {|f| require f}
|
4
|
-
|
5
|
-
ActiveRecord::Migrator.migrations_path = "#{File.dirname(__FILE__)}/migrations"
|
6
|
-
|
7
|
-
RSpec::Matchers.define :have_attribute do |expected|
|
8
|
-
match do |actual|
|
9
|
-
actual[:a]['0'][:name] == expected
|
10
|
-
end
|
11
|
-
|
12
|
-
failure_message_for_should do |actual|
|
13
|
-
"expected: #{actual[:a]['0'][:name]}\n got: #{expected}"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
RSpec::Matchers.define :have_predicate do |expected|
|
18
|
-
match do |actual|
|
19
|
-
actual[:p] == expected
|
20
|
-
end
|
21
|
-
|
22
|
-
failure_message_for_should do |actual|
|
23
|
-
"expected: #{actual[:p]}\n got: #{expected}"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
RSpec::Matchers.define :have_value do |expected|
|
28
|
-
match do |actual|
|
29
|
-
actual[:v]['0'][:value] == expected
|
30
|
-
end
|
31
|
-
|
32
|
-
failure_message_for_should do |actual|
|
33
|
-
"expected: #{actual[:v]['0'][:value]}\n got: #{expected}"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
RSpec::Matchers.define :produce_sql do |expected|
|
38
|
-
match do |actual|
|
39
|
-
actual.to_sql.strip == expected
|
40
|
-
end
|
41
|
-
|
42
|
-
failure_message_for_should do |actual|
|
43
|
-
"expected: #{actual.to_sql}\n got: #{expected}"
|
44
|
-
end
|
1
|
+
require 'nql'
|
2
|
+
|
3
|
+
Dir["#{File.dirname(__FILE__)}/models/**/*.rb"].each {|f| require f}
|
4
|
+
|
5
|
+
ActiveRecord::Migrator.migrations_path = "#{File.dirname(__FILE__)}/migrations"
|
6
|
+
|
7
|
+
RSpec::Matchers.define :have_attribute do |expected|
|
8
|
+
match do |actual|
|
9
|
+
actual[:a]['0'][:name] == expected
|
10
|
+
end
|
11
|
+
|
12
|
+
failure_message_for_should do |actual|
|
13
|
+
"expected: #{actual[:a]['0'][:name]}\n got: #{expected}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
RSpec::Matchers.define :have_predicate do |expected|
|
18
|
+
match do |actual|
|
19
|
+
actual[:p] == expected
|
20
|
+
end
|
21
|
+
|
22
|
+
failure_message_for_should do |actual|
|
23
|
+
"expected: #{actual[:p]}\n got: #{expected}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
RSpec::Matchers.define :have_value do |expected|
|
28
|
+
match do |actual|
|
29
|
+
actual[:v]['0'][:value] == expected
|
30
|
+
end
|
31
|
+
|
32
|
+
failure_message_for_should do |actual|
|
33
|
+
"expected: #{actual[:v]['0'][:value]}\n got: #{expected}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
RSpec::Matchers.define :produce_sql do |expected|
|
38
|
+
match do |actual|
|
39
|
+
actual.to_sql.strip == expected
|
40
|
+
end
|
41
|
+
|
42
|
+
failure_message_for_should do |actual|
|
43
|
+
"expected: #{actual.to_sql}\n got: #{expected}"
|
44
|
+
end
|
45
45
|
end
|