fixturama 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -0
- data/README.md +32 -4
- data/fixturama.gemspec +1 -1
- data/lib/fixturama.rb +48 -20
- data/lib/fixturama/changes.rb +71 -0
- data/lib/fixturama/changes/base.rb +28 -0
- data/lib/fixturama/changes/chain.rb +64 -0
- data/lib/fixturama/changes/chain/actions.rb +31 -0
- data/lib/fixturama/changes/chain/arguments.rb +59 -0
- data/lib/fixturama/changes/chain/raise_action.rb +35 -0
- data/lib/fixturama/changes/chain/return_action.rb +33 -0
- data/lib/fixturama/changes/const.rb +30 -0
- data/lib/fixturama/changes/request.rb +91 -0
- data/lib/fixturama/changes/request/response.rb +62 -0
- data/lib/fixturama/changes/request/responses.rb +22 -0
- data/lib/fixturama/changes/seed.rb +39 -0
- data/lib/fixturama/config.rb +5 -0
- data/lib/fixturama/fixture_error.rb +31 -0
- data/lib/fixturama/loader.rb +1 -0
- data/lib/fixturama/loader/context.rb +1 -0
- data/lib/fixturama/loader/value.rb +1 -0
- data/spec/fixturama/seed_fixture/_spec.rb +1 -0
- data/spec/fixturama/seed_fixture/seed.yml +0 -5
- metadata +34 -34
- data/lib/fixturama/seed.rb +0 -15
- data/lib/fixturama/stubs.rb +0 -79
- data/lib/fixturama/stubs/chain.rb +0 -90
- data/lib/fixturama/stubs/chain/actions.rb +0 -39
- data/lib/fixturama/stubs/chain/actions/raise.rb +0 -21
- data/lib/fixturama/stubs/chain/actions/return.rb +0 -23
- data/lib/fixturama/stubs/chain/arguments.rb +0 -86
- data/lib/fixturama/stubs/const.rb +0 -43
- data/lib/fixturama/stubs/request.rb +0 -98
- data/lib/fixturama/stubs/request/response.rb +0 -43
- data/lib/fixturama/stubs/request/responses.rb +0 -20
- data/lib/fixturama/utils.rb +0 -39
@@ -1,43 +0,0 @@
|
|
1
|
-
class Fixturama::Stubs::Request
|
2
|
-
class Response
|
3
|
-
def to_h
|
4
|
-
{ status: status, body: body, headers: headers }.select { |_, val| val }
|
5
|
-
end
|
6
|
-
|
7
|
-
private
|
8
|
-
|
9
|
-
def initialize(options)
|
10
|
-
@options = options
|
11
|
-
@options = with_error { Hash(options).transform_keys(&:to_sym) }
|
12
|
-
end
|
13
|
-
|
14
|
-
attr_reader :options
|
15
|
-
|
16
|
-
def status
|
17
|
-
with_error("status") { options[:status]&.to_i } || 200
|
18
|
-
end
|
19
|
-
|
20
|
-
def body
|
21
|
-
with_error("body") do
|
22
|
-
case options[:body]
|
23
|
-
when NilClass then nil
|
24
|
-
when Hash then JSON.dump(options[:body])
|
25
|
-
else options[:body].to_s
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def headers
|
31
|
-
with_error("headers") do
|
32
|
-
Hash(options[:headers]).map { |k, v| [k.to_s, v.to_s] }.to_h
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def with_error(part = nil)
|
37
|
-
yield
|
38
|
-
rescue RuntimeError
|
39
|
-
text = ["Cannot extract a response", part, "from #{options}"].join(" ")
|
40
|
-
raise ArgumentError, text, __FILE__, __LINE__ - 1
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
class Fixturama::Stubs::Request
|
2
|
-
class Responses
|
3
|
-
def next
|
4
|
-
list.count > @count ? list[@count].tap { @count += 1 } : list.last
|
5
|
-
end
|
6
|
-
|
7
|
-
private
|
8
|
-
|
9
|
-
def initialize(list)
|
10
|
-
@count = 0
|
11
|
-
list ||= [{ status: 200 }]
|
12
|
-
@list = case list
|
13
|
-
when Array then list.map { |item| Response.new(item).to_h }
|
14
|
-
else [Response.new(list).to_h]
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
attr_reader :list
|
19
|
-
end
|
20
|
-
end
|
data/lib/fixturama/utils.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
module Fixturama
|
2
|
-
module Utils
|
3
|
-
module_function
|
4
|
-
|
5
|
-
def symbolize(item)
|
6
|
-
item.to_s.to_sym
|
7
|
-
end
|
8
|
-
|
9
|
-
def symbolize_hash(data)
|
10
|
-
Hash(data).transform_keys { |key| symbolize(key)}
|
11
|
-
end
|
12
|
-
|
13
|
-
def symbolize_array(data)
|
14
|
-
Array(data).map { |item| symbolize(item) }
|
15
|
-
end
|
16
|
-
|
17
|
-
def constantize(item)
|
18
|
-
Kernel.const_get(item.to_s)
|
19
|
-
end
|
20
|
-
|
21
|
-
def clone(item)
|
22
|
-
item.respond_to?(:dup) ? item.dup : item
|
23
|
-
end
|
24
|
-
|
25
|
-
def array(list)
|
26
|
-
case list
|
27
|
-
when NilClass then []
|
28
|
-
when Array then list
|
29
|
-
else [list]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def matched_hash_args?(actual, expected)
|
34
|
-
return unless actual.is_a?(Hash) && expected.is_a?(Hash)
|
35
|
-
|
36
|
-
expected.all? { |key, val| actual[key] == val }
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|