Skip to content

Commit 5d309b3

Browse files
committed
fix rubocop
1 parent 8f64bac commit 5d309b3

File tree

13 files changed

+234
-241
lines changed

13 files changed

+234
-241
lines changed

spec/unit/lib/membrane/complex_schema_spec.rb

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,36 @@
11
# frozen_string_literal: true
22

3-
require_relative "membrane_spec_helper"
4-
require "membrane"
3+
require_relative 'membrane_spec_helper'
4+
require 'membrane'
55

66
RSpec.describe Membrane do
77
let(:schema) do
88
Membrane::SchemaParser.parse do
9-
{ "ints" => [Integer],
10-
"tf" => bool,
11-
"any" => any,
12-
"1_or_2" => enum(1, 2),
13-
"str_to_str_to_int" => dict(String, dict(String, Integer)),
14-
optional("optional") => bool,
15-
}
9+
{ 'ints' => [Integer],
10+
'tf' => bool,
11+
'any' => any,
12+
'1_or_2' => enum(1, 2),
13+
'str_to_str_to_int' => dict(String, dict(String, Integer)),
14+
optional('optional') => bool }
1615
end
1716
end
1817

1918
let(:valid) do
20-
{ "ints" => [1, 2],
21-
"tf" => false,
22-
"any" => nil,
23-
"1_or_2" => 2,
24-
"optional" => true,
25-
"str_to_str_to_int" => { "ten" => { "twenty" => 20 } },
26-
}
19+
{ 'ints' => [1, 2],
20+
'tf' => false,
21+
'any' => nil,
22+
'1_or_2' => 2,
23+
'optional' => true,
24+
'str_to_str_to_int' => { 'ten' => { 'twenty' => 20 } } }
2725
end
2826

29-
it "should work with complex nested schemas" do
27+
it 'works with complex nested schemas' do
3028
expect(schema.validate(valid)).to be_nil
3129
end
3230

33-
it "should complain about missing keys" do
31+
it 'complains about missing keys' do
3432
required_keys = schema.schemas.keys.dup
35-
required_keys.delete("optional")
33+
required_keys.delete('optional')
3634

3735
required_keys.each do |k|
3836
invalid = valid.dup
@@ -43,10 +41,10 @@
4341
end
4442
end
4543

46-
it "should validate nested maps" do
44+
it 'validates nested maps' do
4745
invalid = valid.dup
4846

49-
invalid["str_to_str_to_int"]["ten"]["twenty"] = "invalid"
47+
invalid['str_to_str_to_int']['ten']['twenty'] = 'invalid'
5048

5149
expect_validation_failure(schema, invalid, /twenty => Expected/)
5250
end

spec/unit/lib/membrane/schema_parser_spec.rb

Lines changed: 66 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,158 +1,158 @@
11
# frozen_string_literal: true
22

3-
require_relative "membrane_spec_helper"
4-
require "membrane"
3+
require_relative 'membrane_spec_helper'
4+
require 'membrane'
55

66
RSpec.describe Membrane::SchemaParser do
77
let(:parser) { Membrane::SchemaParser.new }
88

9-
describe "#deparse" do
10-
it "should call inspect on the value of a Value schema" do
11-
val = "test"
9+
describe '#deparse' do
10+
it 'calls inspect on the value of a Value schema' do
11+
val = 'test'
1212
schema = Membrane::Schemas::Value.new(val)
1313

1414
# Just verify it returns the inspected value
1515
expect(parser.deparse(schema)).to eq val.inspect
1616
end
1717

18-
it "should return 'any' for instance of Membrane::Schemas::Any" do
18+
it "returns 'any' for instance of Membrane::Schemas::Any" do
1919
schema = Membrane::Schemas::Any.new
2020

21-
expect(parser.deparse(schema)).to eq "any"
21+
expect(parser.deparse(schema)).to eq 'any'
2222
end
2323

24-
it "should return 'bool' for instances of Membrane::Schemas::Bool" do
24+
it "returns 'bool' for instances of Membrane::Schemas::Bool" do
2525
schema = Membrane::Schemas::Bool.new
2626

27-
expect(parser.deparse(schema)).to eq "bool"
27+
expect(parser.deparse(schema)).to eq 'bool'
2828
end
2929

30-
it "should call name on the class of a Membrane::Schemas::Class schema" do
30+
it 'calls name on the class of a Membrane::Schemas::Class schema' do
3131
klass = String
3232
schema = Membrane::Schemas::Class.new(klass)
3333

3434
# Just verify it returns the class name
3535
expect(parser.deparse(schema)).to eq klass.name
3636
end
3737

38-
it "should deparse the k/v schemas of a Membrane::Schemas::Dictionary schema" do
38+
it 'deparses the k/v schemas of a Membrane::Schemas::Dictionary schema' do
3939
key_schema = Membrane::Schemas::Class.new(String)
4040
val_schema = Membrane::Schemas::Class.new(Integer)
4141

4242
dict_schema = Membrane::Schemas::Dictionary.new(key_schema, val_schema)
4343

44-
expect(parser.deparse(dict_schema)).to eq "dict(String, Integer)"
44+
expect(parser.deparse(dict_schema)).to eq 'dict(String, Integer)'
4545
end
4646

47-
it "should deparse the element schemas of a Membrane::Schemas::Enum schema" do
47+
it 'deparses the element schemas of a Membrane::Schemas::Enum schema' do
4848
schemas =
4949
[String, Integer, Float].map { |c| Membrane::Schemas::Class.new(c) }
5050

5151
enum_schema = Membrane::Schemas::Enum.new(*schemas)
5252

53-
expect(parser.deparse(enum_schema)).to eq "enum(String, Integer, Float)"
53+
expect(parser.deparse(enum_schema)).to eq 'enum(String, Integer, Float)'
5454
end
5555

56-
it "should deparse the element schema of a Membrane::Schemas::List schema" do
56+
it 'deparses the element schema of a Membrane::Schemas::List schema' do
5757
key_schema = Membrane::Schemas::Class.new(String)
5858
val_schema = Membrane::Schemas::Class.new(Integer)
5959
item_schema = Membrane::Schemas::Dictionary.new(key_schema, val_schema)
6060

6161
list_schema = Membrane::Schemas::List.new(item_schema)
6262

63-
expect(parser.deparse(list_schema)).to eq "[dict(String, Integer)]"
63+
expect(parser.deparse(list_schema)).to eq '[dict(String, Integer)]'
6464
end
6565

66-
it "should deparse elem schemas of a Membrane::Schemas::Record schema" do
66+
it 'deparses elem schemas of a Membrane::Schemas::Record schema' do
6767
str_schema = Membrane::Schemas::Class.new(String)
6868
int_schema = Membrane::Schemas::Class.new(Integer)
6969
dict_schema = Membrane::Schemas::Dictionary.new(str_schema, int_schema)
7070

7171
int_rec_schema = Membrane::Schemas::Record.new({
72-
:str => str_schema,
73-
:dict => dict_schema
74-
})
72+
str: str_schema,
73+
dict: dict_schema
74+
})
7575
rec_schema = Membrane::Schemas::Record.new({
76-
"str" => str_schema,
77-
"rec" => int_rec_schema,
78-
"int" => int_schema
79-
})
80-
81-
exp_deparse =<<EOT
82-
{
83-
"str" => String,
84-
"rec" => {
85-
:str => String,
86-
:dict => dict(String, Integer),
87-
},
88-
"int" => Integer,
89-
}
90-
EOT
76+
'str' => str_schema,
77+
'rec' => int_rec_schema,
78+
'int' => int_schema
79+
})
80+
81+
exp_deparse = <<~EXPECTED_DEPARSE
82+
{
83+
"str" => String,
84+
"rec" => {
85+
:str => String,
86+
:dict => dict(String, Integer),
87+
},
88+
"int" => Integer,
89+
}
90+
EXPECTED_DEPARSE
9191
expect(parser.deparse(rec_schema)).to eq exp_deparse.strip
9292
end
9393

94-
it "should call inspect on regexps for Membrane::Schemas::Regexp" do
94+
it 'calls inspect on regexps for Membrane::Schemas::Regexp' do
9595
regexp_val = /test/
9696
schema = Membrane::Schemas::Regexp.new(regexp_val)
9797

9898
# Just verify it returns the regexp inspected
9999
expect(parser.deparse(schema)).to eq regexp_val.inspect
100100
end
101101

102-
it "should deparse the element schemas of a Membrane::Schemas::Tuple schema" do
102+
it 'deparses the element schemas of a Membrane::Schemas::Tuple schema' do
103103
schemas = [String, Integer].map { |c| Membrane::Schemas::Class.new(c) }
104-
schemas << Membrane::Schemas::Value.new("test")
104+
schemas << Membrane::Schemas::Value.new('test')
105105

106106
enum_schema = Membrane::Schemas::Tuple.new(*schemas)
107107

108108
expect(parser.deparse(enum_schema)).to eq 'tuple(String, Integer, "test")'
109109
end
110110

111-
it "should call inspect on a Membrane::Schemas::Base schema" do
111+
it 'calls inspect on a Membrane::Schemas::Base schema' do
112112
schema = Membrane::Schemas::Base.new
113113
expect(parser.deparse(schema)).to eq schema.inspect
114114
end
115115

116-
it "should raise an error if given a non-schema" do
116+
it 'raises an error if given a non-schema' do
117117
expect do
118118
parser.deparse({})
119119
end.to raise_error(ArgumentError, /Expected instance/)
120120
end
121121
end
122122

123-
describe "#parse" do
124-
it "should leave instances derived from Membrane::Schemas::Base unchanged" do
123+
describe '#parse' do
124+
it 'leaves instances derived from Membrane::Schemas::Base unchanged' do
125125
old_schema = Membrane::Schemas::Any.new
126126

127127
expect(parser.parse { old_schema }).to eq old_schema
128128
end
129129

130-
it "should translate 'any' into Membrane::Schemas::Any" do
130+
it "translates 'any' into Membrane::Schemas::Any" do
131131
schema = parser.parse { any }
132132

133133
expect(schema.class).to eq Membrane::Schemas::Any
134134
end
135135

136-
it "should translate 'bool' into Membrane::Schemas::Bool" do
136+
it "translates 'bool' into Membrane::Schemas::Bool" do
137137
schema = parser.parse { bool }
138138

139139
expect(schema.class).to eq Membrane::Schemas::Bool
140140
end
141141

142-
it "should translate 'enum' into Membrane::Schemas::Enum" do
142+
it "translates 'enum' into Membrane::Schemas::Enum" do
143143
schema = parser.parse { enum(bool, any) }
144144

145145
expect(schema.class).to eq Membrane::Schemas::Enum
146146

147147
expect(schema.elem_schemas.length).to eq 2
148148

149-
elem_schema_classes = schema.elem_schemas.map { |es| es.class }
149+
elem_schema_classes = schema.elem_schemas.map(&:class)
150150

151151
expected_classes = [Membrane::Schemas::Bool, Membrane::Schemas::Any]
152152
expect(elem_schema_classes).to eq expected_classes
153153
end
154154

155-
it "should translate 'dict' into Membrane::Schemas::Dictionary" do
155+
it "translates 'dict' into Membrane::Schemas::Dictionary" do
156156
schema = parser.parse { dict(String, Integer) }
157157

158158
expect(schema.class).to eq Membrane::Schemas::Dictionary
@@ -164,29 +164,29 @@
164164
expect(schema.value_schema.klass).to eq Integer
165165
end
166166

167-
it "should translate 'tuple' into Membrane::Schemas::Tuple" do
167+
it "translates 'tuple' into Membrane::Schemas::Tuple" do
168168
schema = parser.parse { tuple(String, any, Integer) }
169169

170170
expect(schema.class).to eq Membrane::Schemas::Tuple
171171

172172
expect(schema.elem_schemas[0].class).to eq Membrane::Schemas::Class
173173
expect(schema.elem_schemas[0].klass).to eq String
174174

175-
schema.elem_schemas[1].class == Membrane::Schemas::Any
175+
schema.elem_schemas[1].class
176176

177177
expect(schema.elem_schemas[2].class).to eq Membrane::Schemas::Class
178178
expect(schema.elem_schemas[2].klass).to eq Integer
179179
end
180180

181-
it "should translate classes into Membrane::Schemas::Class" do
181+
it 'translates classes into Membrane::Schemas::Class' do
182182
schema = parser.parse { String }
183183

184184
expect(schema.class).to eq Membrane::Schemas::Class
185185

186186
expect(schema.klass).to eq String
187187
end
188188

189-
it "should translate regexps into Membrane::Schemas::Regexp" do
189+
it 'translates regexps into Membrane::Schemas::Regexp' do
190190
regexp = /foo/
191191

192192
schema = parser.parse { regexp }
@@ -196,27 +196,27 @@
196196
expect(schema.regexp).to eq regexp
197197
end
198198

199-
it "should fall back to Membrane::Schemas::Value" do
199+
it 'falls back to Membrane::Schemas::Value' do
200200
schema = parser.parse { 5 }
201201

202202
expect(schema.class).to eq Membrane::Schemas::Value
203203
expect(schema.value).to eq 5
204204
end
205205

206-
describe "when parsing a list" do
207-
it "should raise an error when no element schema is supplied" do
206+
describe 'when parsing a list' do
207+
it 'raises an error when no element schema is supplied' do
208208
expect do
209209
parser.parse { [] }
210210
end.to raise_error(ArgumentError, /must supply/)
211211
end
212212

213-
it "should raise an error when supplied > 1 element schema" do
213+
it 'raises an error when supplied > 1 element schema' do
214214
expect do
215215
parser.parse { [String, String] }
216216
end.to raise_error(ArgumentError, /single schema/)
217217
end
218218

219-
it "should parse '[<expr>]' into Membrane::Schemas::List" do
219+
it "parses '[<expr>]' into Membrane::Schemas::List" do
220220
schema = parser.parse { [String] }
221221

222222
expect(schema.class).to eq Membrane::Schemas::List
@@ -226,37 +226,36 @@
226226
end
227227
end
228228

229-
describe "when parsing a record" do
230-
it "should raise an error if the record is empty" do
229+
describe 'when parsing a record' do
230+
it 'raises an error if the record is empty' do
231231
expect do
232232
parser.parse { {} }
233233
end.to raise_error(ArgumentError, /must supply/)
234234
end
235235

236-
it "should parse '{ <key> => <schema> }' into Membrane::Schemas::Record" do
236+
it "parses '{ <key> => <schema> }' into Membrane::Schemas::Record" do
237237
schema = parser.parse do
238-
{ "string" => String,
239-
"ints" => [Integer],
240-
}
238+
{ 'string' => String,
239+
'ints' => [Integer] }
241240
end
242241

243242
expect(schema.class).to eq Membrane::Schemas::Record
244243

245-
str_schema = schema.schemas["string"]
244+
str_schema = schema.schemas['string']
246245
expect(str_schema.class).to eq Membrane::Schemas::Class
247246
expect(str_schema.klass).to eq String
248247

249-
ints_schema = schema.schemas["ints"]
248+
ints_schema = schema.schemas['ints']
250249
expect(ints_schema.class).to eq Membrane::Schemas::List
251250
expect(ints_schema.elem_schema.class).to eq Membrane::Schemas::Class
252251
expect(ints_schema.elem_schema.klass).to eq Integer
253252
end
254253

255-
it "should handle keys marked with 'optional()'" do
256-
schema = parser.parse { { optional("test") => Integer } }
254+
it "handles keys marked with 'optional()'" do
255+
schema = parser.parse { { optional('test') => Integer } }
257256

258257
expect(schema.class).to eq Membrane::Schemas::Record
259-
expect(schema.optional_keys.to_a).to eq ["test"]
258+
expect(schema.optional_keys.to_a).to eq ['test']
260259
end
261260
end
262261
end

0 commit comments

Comments
 (0)