ruby-jmeter 3.1.06 → 3.1.07

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5db93664cf0240974b592a329ce2e0fce9208676
4
- data.tar.gz: 7f22c6cba517fc8baa43bee0bd56b123bf863dfc
3
+ metadata.gz: e93d14ee553a7e57821b45d87834334e49969f6b
4
+ data.tar.gz: 6b3033cebb68373f0b33a0625fa51f2c3063defd
5
5
  SHA512:
6
- metadata.gz: d608ddc88467133b66be4c943bc1d01f7c005c66eb2750c86f2303d1e63b5baea6d24e38406fd527e96a2d0a9380f2969fd347732968e4a1c33e42b741658e6c
7
- data.tar.gz: a398c2432bc260380769b86d7ae572fcf5a99472f624b174363fecfaac2814d50cb0a8cb2b08748cfebbab13a09a50e2b350ca446e252f02c7ee265986bf9373
6
+ metadata.gz: 93e227a801a68b006880171ee0cbf368db310208611b72114afc951f0b8a5b07f356c3d0671939cf26bd0194e088314dc03a4f555f0f05ad718096b5c506c785
7
+ data.tar.gz: acc5548644827705c11485770ff10bd36b79e3312729cee46088ed70a4e9b4c6d3a0756645c1e87d7442fddc5dedf98db38fff1b99de49eefea3d6dd53b2f664
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
- # RubyJmeter
1
+ # Ruby-JMeter [![Build Status](https://travis-ci.org/flood-io/ruby-jmeter.png)](https://travis-ci.org/flood-io/ruby-jmeter) [![Code Climate](https://codeclimate.com/github/flood-io/ruby-jmeter.png)](https://codeclimate.com/github/flood-io/ruby-jmeter) [![Gem Version](https://badge.fury.io/rb/ruby-jmeter.svg)](http://badge.fury.io/rb/ruby-jmeter)
2
2
 
3
- [![Build Status](https://travis-ci.org/flood-io/ruby-jmeter.png)](https://travis-ci.org/flood-io/ruby-jmeter)
4
- [![Code Climate](https://codeclimate.com/github/flood-io/ruby-jmeter.png)](https://codeclimate.com/github/flood-io/ruby-jmeter)
5
- [![Gem Version](https://badge.fury.io/rb/ruby-jmeter.svg)](http://badge.fury.io/rb/ruby-jmeter)
3
+ > **Ruby-JMeter** is built and maintained by [Flood IO](https://flood.io?utm_source=github), an easy to use load testing platform for any scale of testing.
6
4
 
7
5
  Tired of using the JMeter GUI or looking at hairy XML files?
8
6
 
@@ -198,6 +196,22 @@ test do
198
196
  end
199
197
  ```
200
198
 
199
+ #### User-Defined Cookies
200
+
201
+ The `cookies` method parameters hash supports `user_defined_cookies`:
202
+
203
+ ```ruby
204
+ test do
205
+ cookie1 = { value: 'foo', name: 'bar', domain: 'google.co.uk', path: '/' }
206
+ cookie2 = { value: 'hello', name: 'world', domain: 'google.co.uk', secure: true }
207
+
208
+ cookies user_defined_cookies: [ cookie1, cookie2 ]
209
+ end
210
+ ```
211
+
212
+ `name` and `value` are required. `domain` and `path` are optional and default to blank.
213
+ `secure` is optional and defaults to `false`.
214
+
201
215
  ### Cache
202
216
 
203
217
  You can use the `cache` method to define a Cache Manager:
@@ -6,6 +6,7 @@ test do
6
6
  visit name: 'Home', url: 'https://flooded.io' do
7
7
  regex pattern: "content='(.+?)' name='csrf-token'", name: 'csrf-token', match_number: 1, default: '424242'
8
8
  regex pattern: 'pattern', name: 'jmeter_variable_regex', variable: 'test'
9
+ regex pattern: 'pattern', name: 'jmeter_headers_regex', useHeaders: true
9
10
  end
10
11
  end
11
- end.run(path: '/usr/share/jmeter/bin/', gui: true)
12
+ end.run(path: '/usr/local/share/jmeter-3.1/bin/', gui: true)
@@ -8,7 +8,8 @@ test do
8
8
  assert contains: 'We test, tune and secure your site'
9
9
  assert 'not-contains' => 'Something in frames', scope: 'children'
10
10
  assert 'substring' => 'Something in frames', variable: 'test'
11
+ assert pattern: 'pattern', test_field: 'Assertion.response_headers'
11
12
  end
12
13
  end
13
14
  end
14
- end.run(path: '/usr/share/jmeter/bin/', gui: true)
15
+ end.run(path: '/usr/local/share/jmeter-3.1/bin/', gui: true)
@@ -3,7 +3,14 @@ require 'ruby-jmeter'
3
3
 
4
4
  test do
5
5
  # user parameters with multiple values
6
- visit name: 'Home Page', url: 'https://flooded.io/' do
6
+ post name: 'oauth', url: 'https://flooded.io/api/oauth', raw_body: '${token}' do
7
+ user_parameters names: ['token'],
8
+ thread_values: {
9
+ user_1: [
10
+ '<xml>fidget widget</xml>'
11
+ ]
12
+ }
13
+
7
14
  user_parameters names: ['name1', 'name2'],
8
15
  thread_values: {
9
16
  user_1: [
@@ -18,4 +25,4 @@ test do
18
25
  },
19
26
  per_iteration: true
20
27
  end
21
- end.run(path: '/usr/share/jmeter/bin/', gui: true)
28
+ end.run(path: '/usr/local/share/jmeter-3.1/bin/', gui: true)
@@ -1,11 +1,36 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RubyJmeter
2
4
  class ExtendedDSL < DSL
3
5
  def http_cookie_manager(params = {}, &block)
4
6
  params[:clearEachIteration] = true if params.keys.include? :clear_each_iteration
5
7
 
6
- super
8
+ node = RubyJmeter::HttpCookieManager.new(params)
9
+
10
+ params[:user_defined_cookies]&.each { |cookie| add_cookie_to_collection(cookie, node) }
11
+
12
+ attach_node(node, &block)
7
13
  end
8
14
 
9
15
  alias cookies http_cookie_manager
16
+
17
+ private
18
+
19
+ def add_cookie_to_collection(cookie, node)
20
+ raise 'Cookie name must be provided.' unless cookie[:name]
21
+ raise 'Cookie value must be provided.' unless cookie[:value]
22
+ node.doc.at_xpath('//collectionProp') <<
23
+ Nokogiri::XML(<<-EOS.strip_heredoc).children
24
+ <elementProp name="#{cookie[:name]}" elementType="Cookie" testname="#{cookie[:name]}">
25
+ <stringProp name="Cookie.value">#{cookie[:value]}</stringProp>
26
+ <stringProp name="Cookie.domain">#{cookie[:domain]}</stringProp>
27
+ <stringProp name="Cookie.path">#{cookie[:path]}</stringProp>
28
+ <boolProp name="Cookie.secure">#{cookie[:secure] || false}</boolProp>
29
+ <longProp name="Cookie.expires">0</longProp>
30
+ <boolProp name="Cookie.path_specified">true</boolProp>
31
+ <boolProp name="Cookie.domain_specified">true</boolProp>
32
+ </elementProp>
33
+ EOS
34
+ end
10
35
  end
11
36
  end
@@ -1,3 +1,3 @@
1
1
  module RubyJmeter
2
- VERSION = '3.1.06'
2
+ VERSION = '3.1.07'
3
3
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe 'http_cookie_manager' do
@@ -8,10 +10,160 @@ describe 'http_cookie_manager' do
8
10
  end.to_doc
9
11
  end
10
12
 
11
- let(:cookies_fragment) { doc.search("//CookieManager") }
13
+ let(:cookies_fragment) { doc.search('//CookieManager') }
12
14
 
13
15
  it 'should match on clearEachIteration' do
14
- expect(cookies_fragment.search(".//boolProp[@name='CookieManager.clearEachIteration']").first.text).to eq'true'
16
+ expect(cookies_fragment.search(".//boolProp[@name='CookieManager.clearEachIteration']").first.text).to eq 'true'
17
+ end
18
+ end
19
+
20
+ describe 'the user_defined_cookie option should be respected' do
21
+ context 'when the user_defined_cookie option is empty' do
22
+ let(:doc) do
23
+ test do
24
+ cookies
25
+ end.to_doc
26
+ end
27
+
28
+ let(:cookies_fragment) { doc.search('//CookieManager') }
29
+
30
+ it 'should not populate the collectionProp' do
31
+ expect(cookies_fragment.search("..//collectionProp[@name='CookieManager.cookies']").children.count).to eq 0
32
+ end
33
+ end
34
+
35
+ context 'when the user_defined_cookie option is set' do
36
+ let(:cookie_name) { 'cookie_1' }
37
+ let(:cookie_value) { 'cookie_value' }
38
+ let(:cookie_domain) { 'example.com' }
39
+ let(:cookie_path) { '/' }
40
+ let(:cookie_secure) { true }
41
+
42
+ let(:cookies_fragment) { doc.search('//CookieManager') }
43
+ let(:elements) { cookies_fragment.search("..//collectionProp[@name='CookieManager.cookies']").children }
44
+
45
+ context 'with all the cookie attributes provided' do
46
+ let(:doc) do
47
+ test do
48
+ cookies user_defined_cookies: [
49
+ {
50
+ name: cookie_name,
51
+ value: cookie_value,
52
+ domain: cookie_domain,
53
+ path: cookie_path,
54
+ secure: cookie_secure
55
+ }
56
+ ]
57
+ end.to_doc
58
+ end
59
+
60
+ it 'should add an element to the cookie manager collection' do
61
+ expect(elements.count).to eq 1
62
+ end
63
+
64
+ it 'should add the correct name to the collection element' do
65
+ expect(elements.first.attribute('name').value).to eq cookie_name
66
+ end
67
+
68
+ it 'should add the correct elementType to the collection element' do
69
+ expect(elements.first.attribute('elementType').value).to eq 'Cookie'
70
+ end
71
+
72
+ it 'should add the correct testName to the collection element' do
73
+ expect(elements.first.attribute('testname').value).to eq cookie_name
74
+ end
75
+
76
+ it 'should add a Cookie.value stringProp to the element' do
77
+ expect(elements.first.search("//stringProp[@name='Cookie.value']").text).to eq cookie_value
78
+ end
79
+
80
+ it 'should add a Cookie.domain stringProp to the element' do
81
+ expect(elements.first.search("//stringProp[@name='Cookie.domain']").text).to eq cookie_domain
82
+ end
83
+
84
+ it 'should add a Cookie.path stringProp to the element' do
85
+ expect(elements.first.search("//stringProp[@name='Cookie.path']").text).to eq cookie_path
86
+ end
87
+
88
+ it 'should add a Cookie.secure boolProp to the element' do
89
+ expect(elements.first.search("//boolProp[@name='Cookie.secure']").text).to eq 'true'
90
+ end
91
+
92
+ it 'should add a Cookie.expires longProp to the element' do
93
+ expect(elements.first.search("//longProp[@name='Cookie.expires']").text).to eq '0'
94
+ end
95
+
96
+ it 'should add a Cookie.path_specified boolProp to the element' do
97
+ expect(elements.first.search("//boolProp[@name='Cookie.path_specified']").text).to eq 'true'
98
+ end
99
+
100
+ it 'should add a Cookie.domain_specified boolProp to the element' do
101
+ expect(elements.first.search("//boolProp[@name='Cookie.domain_specified']").text).to eq 'true'
102
+ end
103
+ end
104
+
105
+ context 'without optional cookie attributes provided' do
106
+ let(:doc) do
107
+ test do
108
+ cookies user_defined_cookies: [
109
+ {
110
+ name: cookie_name,
111
+ value: cookie_value
112
+ }
113
+ ]
114
+ end.to_doc
115
+ end
116
+
117
+ it 'should add a default Cookie.secure boolProp to the element' do
118
+ expect(elements.first.search("//boolProp[@name='Cookie.secure']").text).to eq 'false'
119
+ end
120
+
121
+ it 'should add a default Cookie.domain stringProp to the element' do
122
+ expect(elements.first.search("//stringProp[@name='Cookie.domain']").text).to eq ''
123
+ end
124
+
125
+ it 'should add a default Cookie.path stringProp to the element' do
126
+ expect(elements.first.search("//stringProp[@name='Cookie.path']").text).to eq ''
127
+ end
128
+ end
129
+
130
+ context 'without required cookie attributes provided' do
131
+ it 'should raise an error if name is not provided' do
132
+ expect { test { cookies user_defined_cookies: [{ value: cookie_value }] } }
133
+ .to raise_error('Cookie name must be provided.')
134
+ end
135
+ it 'should raise an error if value is not provided' do
136
+ expect { test { cookies user_defined_cookies: [{ name: cookie_name }] } }
137
+ .to raise_error('Cookie value must be provided.')
138
+ end
139
+ end
140
+
141
+ context 'when multiple cookies are set' do
142
+ let(:doc) do
143
+ test do
144
+ cookies user_defined_cookies: [
145
+ {
146
+ name: cookie_name,
147
+ value: cookie_value,
148
+ domain: cookie_domain,
149
+ path: cookie_path,
150
+ secure: cookie_secure
151
+ },
152
+ {
153
+ name: cookie_name,
154
+ value: cookie_value,
155
+ domain: cookie_domain,
156
+ path: cookie_path,
157
+ secure: cookie_secure
158
+ }
159
+ ]
160
+ end.to_doc
161
+ end
162
+
163
+ it 'should add multiple elements to the cookie manager collection' do
164
+ expect(elements.count).to eq 2
165
+ end
166
+ end
15
167
  end
16
168
  end
17
169
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-jmeter
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.06
4
+ version: 3.1.07
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Koopmans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-30 00:00:00.000000000 Z
11
+ date: 2017-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -333,7 +333,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
333
333
  version: '0'
334
334
  requirements: []
335
335
  rubyforge_project:
336
- rubygems_version: 2.6.12
336
+ rubygems_version: 2.5.1
337
337
  signing_key:
338
338
  specification_version: 4
339
339
  summary: Ruby based DSL for writing JMeter test plans