form_robot 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/form_robot/robot.rb +7 -6
- data/lib/form_robot/version.rb +1 -1
- data/test/lib/form_robot/encoding_test.rb +2 -2
- data/test/lib/form_robot/json_test.rb +28 -0
- data/test/lib/form_robot/robot_test.rb +9 -9
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfe0f0db451116944eb4652cae87febc70f036a4
|
4
|
+
data.tar.gz: d54bb3c76b69f9d763a84752798d9baf52aa77db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 777bafd297b3cd932c8128729a5fbb0dd4ecbdb10baa99bbda424cd89679eae37ec32ea8cedc47801682b0f26aa2dc1a73065c1c8a0afe42efcccce4f0945044
|
7
|
+
data.tar.gz: f952dffee9bddab2bce259339f598d721c848b0b25655f73557e6e36320c6a7b9dd38cb856b09c5db73a7b6393496adfaf96c47650bf18b24c4b12b3b28e9d5e
|
data/CHANGELOG.md
CHANGED
data/lib/form_robot/robot.rb
CHANGED
@@ -14,6 +14,7 @@ class Robot
|
|
14
14
|
task = instructions
|
15
15
|
@was_successful = carry_out_single( task )
|
16
16
|
@failure_reason = 'Unable to ' + ( task[:description] || 'perform task' ) unless @was_successful
|
17
|
+
@was_successful
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
@@ -22,16 +23,16 @@ class Robot
|
|
22
23
|
end
|
23
24
|
|
24
25
|
private
|
25
|
-
def carry_out_single (
|
26
|
-
|
27
|
-
|
26
|
+
def carry_out_single ( args = {} )
|
27
|
+
page = args.has_key?( 'go_to_url' ) ? @mech.get( args['go_to_url'] ) : @mech.page
|
28
|
+
form_with_params = page.forms.detect do |form|
|
29
|
+
args['enter_params'].keys.all? do |key|
|
28
30
|
form.keys.include? key
|
29
31
|
end
|
30
32
|
end
|
31
|
-
form_with_params.set_fields( enter_params )
|
33
|
+
form_with_params.set_fields( args['enter_params'] )
|
32
34
|
form_with_params.submit
|
33
35
|
|
34
|
-
@mech.page.
|
35
|
-
look_for_text ? @mech.page.parser.to_s.match(look_for_text) : true
|
36
|
+
args.has_key?( 'look_for_text' ) ? @mech.page.parser.to_s.match( args['look_for_text'] ) : true
|
36
37
|
end
|
37
38
|
end
|
data/lib/form_robot/version.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
describe Robot do
|
6
|
+
r = Robot.new
|
7
|
+
|
8
|
+
it 'must be able to read data parsed from JSON' do
|
9
|
+
json = '{
|
10
|
+
"instructions": [
|
11
|
+
{
|
12
|
+
"go_to_url": "http://www.google.com",
|
13
|
+
"enter_params": {
|
14
|
+
"q": "Ruby on Rails"
|
15
|
+
}
|
16
|
+
},
|
17
|
+
{
|
18
|
+
"enter_params": {
|
19
|
+
"q": "Perl Dancer"
|
20
|
+
}
|
21
|
+
}
|
22
|
+
]
|
23
|
+
}'
|
24
|
+
instructions = JSON.parse(json)
|
25
|
+
r.carry_out(instructions['instructions'])
|
26
|
+
assert_match( /www\.perldancer\.org/, r.last_response )
|
27
|
+
end
|
28
|
+
end
|
@@ -5,11 +5,11 @@ describe Robot do
|
|
5
5
|
|
6
6
|
it 'must be able to do a Google search' do
|
7
7
|
instructions = {
|
8
|
-
go_to_url
|
9
|
-
enter_params
|
8
|
+
'go_to_url' => 'http://www.google.com',
|
9
|
+
'enter_params' => {
|
10
10
|
'q' => 'RubyGems',
|
11
11
|
},
|
12
|
-
look_for_text
|
12
|
+
'look_for_text' => 'rubygems.org',
|
13
13
|
};
|
14
14
|
robot.carry_out(instructions)
|
15
15
|
assert robot.was_successful
|
@@ -17,18 +17,18 @@ describe Robot do
|
|
17
17
|
|
18
18
|
it 'must be able to handle multiple instructions' do
|
19
19
|
instructions = [{
|
20
|
-
go_to_url
|
21
|
-
enter_params
|
20
|
+
'go_to_url' => 'http://www.linkedin.com/',
|
21
|
+
'enter_params' => {
|
22
22
|
'first' => 'Keith',
|
23
23
|
'last' => 'Broughton',
|
24
24
|
},
|
25
|
-
look_for_text
|
25
|
+
'look_for_text' => 'Republic of Ireland',
|
26
26
|
}, {
|
27
|
-
go_to_url
|
28
|
-
enter_params
|
27
|
+
'go_to_url' => 'https://github.com/',
|
28
|
+
'enter_params' => {
|
29
29
|
'q' => 'mongoid',
|
30
30
|
},
|
31
|
-
look_for_text
|
31
|
+
'look_for_text' => 'Ruby ODM framework for MongoDB',
|
32
32
|
}];
|
33
33
|
robot.carry_out(instructions)
|
34
34
|
assert robot.was_successful
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: form_robot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keith Broughton
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- lib/form_robot/robot.rb
|
72
72
|
- lib/form_robot/version.rb
|
73
73
|
- test/lib/form_robot/encoding_test.rb
|
74
|
+
- test/lib/form_robot/json_test.rb
|
74
75
|
- test/lib/form_robot/robot_test.rb
|
75
76
|
- test/lib/form_robot/version_test.rb
|
76
77
|
- test/test_helper.rb
|
@@ -101,6 +102,7 @@ summary: The Form Robot gem accepts a list of instructions to perform against a
|
|
101
102
|
of URLs and HTML forms.
|
102
103
|
test_files:
|
103
104
|
- test/lib/form_robot/encoding_test.rb
|
105
|
+
- test/lib/form_robot/json_test.rb
|
104
106
|
- test/lib/form_robot/robot_test.rb
|
105
107
|
- test/lib/form_robot/version_test.rb
|
106
108
|
- test/test_helper.rb
|