screenplay 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63bce83d0f98bb3b47361fe3e9fb1e3faf2f41c3
4
- data.tar.gz: 119bf21f6e38ff112ba28e9a27be71508f933def
3
+ metadata.gz: b226d59c75415b22f69511c0c26d5c123ef7148c
4
+ data.tar.gz: 9c15ef66099947510117fd11bc442b67f71139f6
5
5
  SHA512:
6
- metadata.gz: 5a887b644db3c1db7424c5e53f836688f0a4216273b2be93ccc782d3d0267adff931f67ba8fab5c6e5ef6d2d64826bcf95d3b5324032f1946e0243f5f7e52941
7
- data.tar.gz: 85c1a1a3a264aa50eb481e3213d0eac55ca88df8120e4adc88e2fbb45bf6a7ad53a0792ceff56824a58b19edd073ae0999b833ff00abc484742d9516d1b91c01
6
+ metadata.gz: 9fad414d66f8a9c71980d839628e08da5d1ac7c40244db69ec16607971f69df44525baa270f8901557d0d69de2f8630799035300e45484826469fa84d4c7e9c3
7
+ data.tar.gz: 4e40b8ec65f9c2d1319a852f9357ddb0a6d9c00013d4770153f2549a91c3549125e47df634fe68d1405fa13a9933e0a5e7513f33c4e03269653b972a1243e85f
data/Gemfile CHANGED
@@ -2,5 +2,8 @@ source 'http://rubygems.org'
2
2
 
3
3
  gem 'rest-client', '~> 1.7.3'
4
4
  gem 'highline', '~> 1.6.21'
5
+ gem 'mime-types', '~> 2.99.2'
6
+
7
+ gem 'minitest'
5
8
 
6
9
 
@@ -16,7 +16,8 @@ module Screenplay
16
16
  def configure(config)
17
17
  @url = config[:url].to_s
18
18
  @url += '/' unless @url.end_with?('/')
19
- @headers = config[:headers] || {}
19
+ @headers = {}
20
+ @config = config
20
21
  @cookies = nil
21
22
  end
22
23
 
@@ -28,7 +29,8 @@ module Screenplay
28
29
  data = params[:data] || {} rescue {}
29
30
  data = input if (data.is_a?(String)) && (data == '$input')
30
31
  data.stringify_keys!
31
- headers = @headers
32
+ headers = {}
33
+ headers['Content-Type'] = @config[:content_type] if (!@config[:content_type].nil?)
32
34
  headers[:cookie] = @cookies unless @cookies.nil?
33
35
  url = @url + path.to_s.replace_vars(input)
34
36
  if ([:get, :head, :delete].include?(method))
@@ -36,10 +38,12 @@ module Screenplay
36
38
  data = {}
37
39
  end
38
40
 
39
- if (headers['Content-Type'.to_sym] == 'application/json')
41
+ if (headers['Content-Type'] == 'application/json')
40
42
  data = JSON.generate(data)
41
43
  end
42
44
 
45
+ puts "\nAPI - #{method.to_s.upcase} - #{url}: #{data}" if Screenplay.options[:debug]
46
+
43
47
  begin
44
48
  response = RestClient::Request.execute({
45
49
  url: url,
@@ -16,10 +16,12 @@ module Screenplay
16
16
  @cache.clear
17
17
  elsif action == :set
18
18
  values.each { | cache_key, input_key |
19
- @cache[cache_key.to_sym] = (input_key == '$input'.to_sym) ? input : input[input_key.to_sym]
19
+ @cache[cache_key] = (input_key == '$input'.to_sym) ? input : input.get_value_from_path(input_key)
20
+ puts "\nSet cache #{cache_key} to #{@cache[cache_key]}" if Screenplay.options[:debug]
20
21
  }
21
22
  elsif (action == :merge || action == :get)
22
23
  values.each { | input_key, cache_key |
24
+ puts "\nSet #{input_key.to_sym} to #{@cache[cache_key.to_sym]} from cache key #{cache_key}" if Screenplay.options[:debug]
23
25
  output[input_key.to_sym] = @cache[cache_key.to_sym]
24
26
  }
25
27
  end
@@ -35,8 +35,7 @@ module Screenplay
35
35
  test = test.to_s[4..-1] unless expects
36
36
  method = "test_#{test}".to_sym
37
37
  raise UnknownTestException.new(test) if !respond_to?(method)
38
- raise UnknownInputKeyException.new(test, key) unless input.include?(key.to_sym)
39
- a = input[key.to_sym]
38
+ a = input.get_value_from_path(key)
40
39
  raise TestFailedException.new(test, a, b) unless (public_send(method, a, b) == expects)
41
40
  }
42
41
  }
@@ -53,6 +53,27 @@ class Hash
53
53
  return self
54
54
  end
55
55
 
56
+ def get_value_from_path(path, sep_char = '.')
57
+ node, rest = path.to_s.split(sep_char, 2)
58
+ index = node.gsub(/(^.*\[|\]$)/, '')
59
+ value = nil
60
+ if node == index
61
+ value = self[node.to_sym] || self[node.to_s]
62
+ elsif index.numeric?
63
+ node.gsub!(/\[(\w+)\]$/, '')
64
+ if self.include?(node.to_sym) && self[node.to_sym].is_a?(Array)
65
+ value = self[node.to_sym][index.to_i]
66
+ elsif self.include?(node.to_s) && self[node.to_s].is_a?(Array)
67
+ value = self[node.to_s][index.to_i]
68
+ else
69
+ value = nil
70
+ end
71
+ end
72
+ return nil if value.nil?
73
+ return value if rest.nil? || rest.empty?
74
+ return value.is_a?(Hash) ? value.get_value_from_path(rest, sep_char) : nil
75
+ end
76
+
56
77
  end
57
78
 
58
79
 
@@ -102,12 +123,11 @@ class String
102
123
  (self.length > max_length) ? self.to_s[0..max_length].gsub(/[^\w]\w+\s*$/, '...') : self.to_s
103
124
  end
104
125
 
105
- def replace_vars!(input)
126
+ def replace_vars!(input, sep_char = '.')
106
127
  input = {} unless input.is_a?(Hash)
107
- return if input.empty?
108
- matches = {}
109
- input.each { | k, v | matches['#{' + k.to_s + '}'] = v.to_s }
110
- self.gsub!(/\#({\w+})/, matches)
128
+ self.gsub!(/\#({[\w#{Regexp.escape(sep_char)}]+})/) { | key |
129
+ input.get_value_from_path(key.delete("{}#"))
130
+ }
111
131
  end
112
132
 
113
133
  def replace_vars(input)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: screenplay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taco Jan Osinga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-28 00:00:00.000000000 Z
11
+ date: 2016-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  version: '0'
82
82
  requirements: []
83
83
  rubyforge_project:
84
- rubygems_version: 2.2.2
84
+ rubygems_version: 2.6.6
85
85
  signing_key:
86
86
  specification_version: 4
87
87
  summary: Screenplay