marty_rspec 0.0.2 → 0.0.3
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 +4 -4
- data/README.md +48 -15
- data/lib/marty_rspec/components/netzke_combobox.rb +58 -0
- data/lib/marty_rspec/{netzke_grid.rb → components/netzke_grid.rb} +9 -17
- data/lib/marty_rspec/util.rb +56 -38
- data/lib/marty_rspec/version.rb +1 -1
- data/lib/marty_rspec.rb +3 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5f5f84a781635900e1ceef086b902ee8b92db76
|
4
|
+
data.tar.gz: 1ac4b61457b1d88cb89565135bd4f20e5316a5eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 427b2d76f37f080a4eeed3c95661f65e7c2784f5236e61c81e89b1a1d3791add97500542c3b38750a40e1eae8d903dad0f519f98a505e3e7ff2e0007aa40429f
|
7
|
+
data.tar.gz: 8f918c4a5e0005b8291bb379dd1af1ffcabd9a3836210fd713d2418b15cc33c55f7369cd78bda9d4815584127827b9c5de681938fd569f6b9581297aceb3dc21
|
data/README.md
CHANGED
@@ -1,8 +1,51 @@
|
|
1
|
-
#
|
1
|
+
# Marty RSpec
|
2
2
|
|
3
|
-
|
3
|
+
is a set of helper methods for integration/feature testing for the [Marty](https://github.com/arman000/marty) framework. In particular, it primarily maps javascript functions to provide Capybara-like behavior for Netzke/ExtJS components.
|
4
4
|
|
5
|
-
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
On the macro-level, Marty RSpec functionality can be broken up into 6 pieces.
|
8
|
+
|
9
|
+
1. General Utility functions
|
10
|
+
|
11
|
+
examples include log_in, press(button)
|
12
|
+
|
13
|
+
2. Wait functions
|
14
|
+
|
15
|
+
because netzke/extjs requires execute_scripts all over the place, and because this causes intermittent timing failures
|
16
|
+
|
17
|
+
3. Netzke Component Utility functions
|
18
|
+
|
19
|
+
first, call `c = netzke_find(name, component_type)`
|
20
|
+
note that this doesn't actually 'find' the component a la Capybara. Instead, it prepares the javascript to be used for the particular component helper method. So, in order for any javascript to run, you would need to call (on a grid), for example, `c.row_count`
|
21
|
+
|
22
|
+
1. component_type = 'gridpanel'
|
23
|
+
|
24
|
+
this is the default
|
25
|
+
|
26
|
+
2. component_type = 'combobox'
|
27
|
+
|
28
|
+
4. Custom Capybara selectors
|
29
|
+
|
30
|
+
for using Capybara find on commonly used netzke/extjs DOM items
|
31
|
+
|
32
|
+
5. Custom RSpec Matchers
|
33
|
+
|
34
|
+
6. RSpec-by formatter
|
35
|
+
|
36
|
+
this is actually an external gem that provides verbose RSpec formatter with benchmarking capabilities. You can wrap bits of longer feature tests in a block. RSpec will print the messages out with how many seconds each block took to complete.
|
37
|
+
|
38
|
+
```
|
39
|
+
# the beginning of your awesome test
|
40
|
+
by 'your output message here' do
|
41
|
+
# some test stuff here
|
42
|
+
end
|
43
|
+
|
44
|
+
and_by 'your next step' do
|
45
|
+
# some other test stuff here
|
46
|
+
end
|
47
|
+
# the rest of your awesome test
|
48
|
+
```
|
6
49
|
|
7
50
|
## Installation
|
8
51
|
|
@@ -14,25 +57,15 @@ gem 'marty_rspec'
|
|
14
57
|
|
15
58
|
And then execute:
|
16
59
|
|
17
|
-
$ bundle
|
60
|
+
$ bundle install
|
18
61
|
|
19
62
|
Or install it yourself as:
|
20
63
|
|
21
64
|
$ gem install marty_rspec
|
22
65
|
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
TODO: Write usage instructions here
|
26
|
-
|
27
|
-
## Development
|
28
|
-
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
-
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
-
|
33
66
|
## Contributing
|
34
67
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
68
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sleepn247/marty_rspec.
|
36
69
|
|
37
70
|
|
38
71
|
## License
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'capybara/dsl'
|
2
|
+
require 'rspec/matchers'
|
3
|
+
|
4
|
+
module MartyRSpec
|
5
|
+
module Components
|
6
|
+
class NetzkeCombobox
|
7
|
+
include Util
|
8
|
+
include Capybara::DSL
|
9
|
+
include RSpec::Matchers
|
10
|
+
|
11
|
+
attr_reader :name, :combobox
|
12
|
+
|
13
|
+
def initialize(name)
|
14
|
+
@name = name
|
15
|
+
if /^\d+$/.match(name)
|
16
|
+
@combobox = ext_find('combobox', nil, name)
|
17
|
+
else
|
18
|
+
@combobox = ext_combo(name)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def select_values(values)
|
23
|
+
run_js <<-JS
|
24
|
+
var values = #{values.split(/,\s*/)};
|
25
|
+
#{combobox}
|
26
|
+
var arr = new Array();
|
27
|
+
for(var i=0; i < values.length; i++) {
|
28
|
+
arr[i] = combo.findRecordByDisplay(values[i]);
|
29
|
+
}
|
30
|
+
combo.select(arr);
|
31
|
+
if (combo.isExpanded) {
|
32
|
+
combo.onTriggerClick();
|
33
|
+
};
|
34
|
+
return true;
|
35
|
+
JS
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_values
|
39
|
+
run_js <<-JS
|
40
|
+
var values = [];
|
41
|
+
#{combobox}
|
42
|
+
combo.getStore().each(
|
43
|
+
function(r) { values.push(r.data.text || r.data.field1); });
|
44
|
+
return values;
|
45
|
+
JS
|
46
|
+
end
|
47
|
+
|
48
|
+
def click
|
49
|
+
run_js <<-JS
|
50
|
+
#{combobox}
|
51
|
+
combo.onTriggerClick();
|
52
|
+
return true;
|
53
|
+
JS
|
54
|
+
wait_for_element { !ajax_loading? }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -2,24 +2,21 @@ require 'capybara/dsl'
|
|
2
2
|
require 'rspec/matchers'
|
3
3
|
|
4
4
|
module MartyRSpec
|
5
|
-
module
|
6
|
-
|
7
|
-
NetzkeGridNode.new(name, grid_type)
|
8
|
-
end
|
9
|
-
|
10
|
-
class NetzkeGridNode
|
5
|
+
module Components
|
6
|
+
class NetzkeGrid
|
11
7
|
include Util
|
12
8
|
include Capybara::DSL
|
13
9
|
include RSpec::Matchers
|
14
10
|
|
15
11
|
attr_reader :name, :grid
|
16
12
|
|
17
|
-
def initialize(name,
|
13
|
+
def initialize(name, c_type)
|
14
|
+
# for now, also allows treepanel
|
18
15
|
@name = name
|
19
16
|
if /^\d+$/.match(name)
|
20
|
-
@grid = ext_find(
|
17
|
+
@grid = ext_find(c_type, nil, name)
|
21
18
|
else
|
22
|
-
@grid = ext_find(ext_arg(
|
19
|
+
@grid = ext_find(ext_arg(c_type, name: name))
|
23
20
|
end
|
24
21
|
end
|
25
22
|
|
@@ -38,12 +35,7 @@ module MartyRSpec
|
|
38
35
|
res.to_i
|
39
36
|
end
|
40
37
|
|
41
|
-
|
42
|
-
res = run_js <<-JS
|
43
|
-
return #{grid}.getStore().getTotalCount();
|
44
|
-
JS
|
45
|
-
res.to_i
|
46
|
-
end
|
38
|
+
alias :row_total :row_count
|
47
39
|
|
48
40
|
def row_modified_count
|
49
41
|
res = run_js <<-JS
|
@@ -66,8 +58,8 @@ module MartyRSpec
|
|
66
58
|
JS
|
67
59
|
end
|
68
60
|
|
69
|
-
def col_values(col, cnt, init=0)
|
70
|
-
#does not validate the # of rows
|
61
|
+
def col_values(col, cnt=row_count, init=0)
|
62
|
+
# NOTE: does not validate the # of rows
|
71
63
|
run_js <<-JS
|
72
64
|
var result = [];
|
73
65
|
for (var i = #{init}; i < #{init.to_i + cnt.to_i}; i++) {
|
data/lib/marty_rspec/util.rb
CHANGED
@@ -2,15 +2,6 @@ module MartyRSpec
|
|
2
2
|
module Util
|
3
3
|
MAX_WAIT_TIME = 5.0
|
4
4
|
|
5
|
-
# essentially works as documentation & wait
|
6
|
-
def by message, level=0
|
7
|
-
wait_for_ready(10)
|
8
|
-
pending(message) unless block_given?
|
9
|
-
yield
|
10
|
-
end
|
11
|
-
|
12
|
-
alias and_by by
|
13
|
-
|
14
5
|
# navigation helpers
|
15
6
|
def ensure_on(path)
|
16
7
|
visit(path) unless current_path == path
|
@@ -61,6 +52,15 @@ module MartyRSpec
|
|
61
52
|
find(:xpath, '//img[contains(@class, "x-tool-close")]', wait: 5).click
|
62
53
|
end
|
63
54
|
|
55
|
+
def zoom_out
|
56
|
+
el = find(:body, match: :first)
|
57
|
+
el.native.send_keys([:control, '0'])
|
58
|
+
el.native.send_keys([:control, '-'])
|
59
|
+
el.native.send_keys([:control, '-'])
|
60
|
+
el.native.send_keys([:control, '-'])
|
61
|
+
end
|
62
|
+
|
63
|
+
#####
|
64
64
|
def wait_for_ready wait_time = nil
|
65
65
|
if wait_time
|
66
66
|
find(:status, 'Ready', wait: wait_time)
|
@@ -81,14 +81,6 @@ module MartyRSpec
|
|
81
81
|
JS
|
82
82
|
end
|
83
83
|
|
84
|
-
def zoom_out
|
85
|
-
el = find(:body, match: :first)
|
86
|
-
el.native.send_keys([:control, '0'])
|
87
|
-
el.native.send_keys([:control, '-'])
|
88
|
-
el.native.send_keys([:control, '-'])
|
89
|
-
el.native.send_keys([:control, '-'])
|
90
|
-
end
|
91
|
-
|
92
84
|
def wait_for_element(seconds_to_wait = 2.0, sleeptime = 0.1)
|
93
85
|
res = nil
|
94
86
|
start_time = current_time = Time.now
|
@@ -104,6 +96,18 @@ module MartyRSpec
|
|
104
96
|
res
|
105
97
|
end
|
106
98
|
|
99
|
+
#####
|
100
|
+
# note that netzke_find doesn't actually find the component (as in Capybara)
|
101
|
+
# instead, it prepares the javascript to be run on the component object
|
102
|
+
def netzke_find(name, c_type = 'gridpanel')
|
103
|
+
case c_type
|
104
|
+
when 'combobox'
|
105
|
+
MartyRSpec::Components::NetzkeCombobox.new(name)
|
106
|
+
else
|
107
|
+
MartyRSpec::Components::NetzkeGrid.new(name, c_type)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
107
111
|
def run_js js_str, seconds_to_wait = MAX_WAIT_TIME, sleeptime = 0.1
|
108
112
|
result = wait_for_element(seconds_to_wait, sleeptime) do
|
109
113
|
page.document.synchronize { @res = page.execute_script(js_str) }
|
@@ -144,9 +148,11 @@ module MartyRSpec
|
|
144
148
|
result.split(' ')[1].to_i
|
145
149
|
end
|
146
150
|
|
151
|
+
private
|
147
152
|
def simple_escape! text
|
148
153
|
text.gsub!(/(\r\n|\n)/, "\\n")
|
149
154
|
text.gsub!(/\t/, "\\t")
|
155
|
+
text.gsub!(/"/, '\"')
|
150
156
|
end
|
151
157
|
|
152
158
|
def paste text, textarea
|
@@ -157,6 +163,7 @@ module MartyRSpec
|
|
157
163
|
run_js <<-JS
|
158
164
|
#{ext_var(ext_find(ext_arg('textarea', name: textarea)), 'area')}
|
159
165
|
area.setValue("#{text}");
|
166
|
+
return true;
|
160
167
|
JS
|
161
168
|
end
|
162
169
|
|
@@ -167,7 +174,24 @@ module MartyRSpec
|
|
167
174
|
!res[:class].match(/disabled/).nil?
|
168
175
|
end
|
169
176
|
|
170
|
-
#
|
177
|
+
# Field edit/Key in Helpers
|
178
|
+
def type_in(type_s, el_id)
|
179
|
+
el = find_by_id("#{el_id}")
|
180
|
+
el.native.clear()
|
181
|
+
type_s.each_char do |key|
|
182
|
+
el.native.send_keys(key)
|
183
|
+
end
|
184
|
+
el.send_keys(:enter)
|
185
|
+
end
|
186
|
+
|
187
|
+
def press_key_in(key, el_id)
|
188
|
+
kd = key.downcase
|
189
|
+
use_key = ['enter', 'return'].include?(kd) ? kd.to_sym : key
|
190
|
+
el = find_by_id("#{el_id}")
|
191
|
+
el.native.send_keys(use_key)
|
192
|
+
end
|
193
|
+
|
194
|
+
# Netzke component lookups, arguments for helper methods
|
171
195
|
# (i.e. component) require JS scripts instead of objects
|
172
196
|
def ext_arg(component, c_args = {})
|
173
197
|
res = component
|
@@ -233,25 +257,13 @@ module MartyRSpec
|
|
233
257
|
JS
|
234
258
|
end
|
235
259
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
el.native.clear()
|
240
|
-
type_s.each_char do |key|
|
241
|
-
el.native.send_keys(key)
|
242
|
-
end
|
243
|
-
el.send_keys(:enter)
|
244
|
-
end
|
245
|
-
|
246
|
-
def press_key_in(key, el_id)
|
247
|
-
kd = key.downcase
|
248
|
-
use_key = ['enter', 'return'].include?(kd) ? kd.to_sym : key
|
249
|
-
el = find_by_id("#{el_id}")
|
250
|
-
el.native.send_keys(use_key)
|
251
|
-
end
|
260
|
+
##############
|
261
|
+
# DEPRECATED #
|
262
|
+
##############
|
252
263
|
|
253
|
-
# Combobox Helpers
|
264
|
+
# Combobox Helpers, now separate component, like grid
|
254
265
|
def select_combobox(values, combo_label)
|
266
|
+
warn "[DEPRECATED] use netzke_find('#{combo_label}', 'combobox').select_values(values)"
|
255
267
|
run_js <<-JS
|
256
268
|
var values = #{values.split(/,\s*/)};
|
257
269
|
#{ext_combo(combo_label)}
|
@@ -261,11 +273,15 @@ module MartyRSpec
|
|
261
273
|
arr[i] = combo.findRecordByDisplay(values[i]);
|
262
274
|
}
|
263
275
|
combo.select(arr);
|
264
|
-
if (combo.isExpanded) {
|
276
|
+
if (combo.isExpanded) {
|
277
|
+
combo.onTriggerClick();
|
278
|
+
return true;
|
279
|
+
};
|
265
280
|
JS
|
266
281
|
end
|
267
282
|
|
268
283
|
def combobox_values(combo_label)
|
284
|
+
warn "[DEPRECATED] use netzke_find('#{combo_label}', 'combobox').get_values"
|
269
285
|
run_js <<-JS
|
270
286
|
#{ext_combo(combo_label)}
|
271
287
|
var values = [];
|
@@ -276,16 +292,18 @@ module MartyRSpec
|
|
276
292
|
end
|
277
293
|
|
278
294
|
def click_combobox combo_label
|
295
|
+
warn "[DEPRECATED] use netzke_find('#{combo_label}', 'combobox').click"
|
279
296
|
run_js <<-JS
|
280
297
|
#{ext_combo(combo_label)}
|
281
298
|
combo.onTriggerClick();
|
299
|
+
return true;
|
282
300
|
JS
|
283
301
|
wait_for_element { !ajax_loading? }
|
284
302
|
end
|
285
303
|
|
286
304
|
def custom_selectors
|
287
|
-
#
|
288
|
-
warn "[DEPRECATED]
|
305
|
+
# automatically loaded now
|
306
|
+
warn "[DEPRECATED] automatically loaded"
|
289
307
|
end
|
290
308
|
end
|
291
309
|
end
|
data/lib/marty_rspec/version.rb
CHANGED
data/lib/marty_rspec.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'marty_rspec/version'
|
2
2
|
require 'marty_rspec/util'
|
3
|
-
require 'marty_rspec/netzke_grid'
|
3
|
+
require 'marty_rspec/components/netzke_grid'
|
4
|
+
require 'marty_rspec/components/netzke_combobox'
|
4
5
|
require 'marty_rspec/custom_matchers'
|
5
6
|
require 'marty_rspec/custom_selectors'
|
7
|
+
require 'rspec/by'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: marty_rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masaki Matsuo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-by
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
description:
|
28
42
|
email: masaki.matsuo@pnmac.com
|
29
43
|
executables: []
|
@@ -36,9 +50,10 @@ files:
|
|
36
50
|
- README.md
|
37
51
|
- Rakefile
|
38
52
|
- lib/marty_rspec.rb
|
53
|
+
- lib/marty_rspec/components/netzke_combobox.rb
|
54
|
+
- lib/marty_rspec/components/netzke_grid.rb
|
39
55
|
- lib/marty_rspec/custom_matchers.rb
|
40
56
|
- lib/marty_rspec/custom_selectors.rb
|
41
|
-
- lib/marty_rspec/netzke_grid.rb
|
42
57
|
- lib/marty_rspec/util.rb
|
43
58
|
- lib/marty_rspec/version.rb
|
44
59
|
- spec/marty_rspec_spec.rb
|