form_robot 0.0.3 → 0.0.4

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: 31bee54546f4b5e857693c61fe336fe1fa6f478f
4
- data.tar.gz: 87af9b8860f8c764570e7b1fffaf3fdb9027664f
3
+ metadata.gz: dfe0f0db451116944eb4652cae87febc70f036a4
4
+ data.tar.gz: d54bb3c76b69f9d763a84752798d9baf52aa77db
5
5
  SHA512:
6
- metadata.gz: 25f760bdf6dfd4d1def35b27d88c26f2179c8adece29b0d50c4d3a1a4b326e21fd56ac9f0f1069b3630bffbb1f176549340cffbadc2a155cd22036ceca053424
7
- data.tar.gz: f72b3754c6cc93a39e9bc5376883ad3996efa2213d89694e37db79423767a6a5fcf6cf5f8066fc93982b57e76d3a760f1becd05997c62329dd14c71ba569f211
6
+ metadata.gz: 777bafd297b3cd932c8128729a5fbb0dd4ecbdb10baa99bbda424cd89679eae37ec32ea8cedc47801682b0f26aa2dc1a73065c1c8a0afe42efcccce4f0945044
7
+ data.tar.gz: f952dffee9bddab2bce259339f598d721c848b0b25655f73557e6e36320c6a7b9dd38cb856b09c5db73a7b6393496adfaf96c47650bf18b24c4b12b3b28e9d5e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.4
4
+
5
+ Use string hash keys everywhere, because of the way that JSON parses and because of the way that Mechanize set field values
6
+
3
7
  ## 0.0.3
4
8
 
5
9
  Make sure that the robot's response is in UTF-8
@@ -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 ( go_to_url: nil, enter_params: {}, look_for_text: nil, description: nil )
26
- form_with_params = @mech.get( go_to_url ).forms.detect do |form|
27
- enter_params.keys.all? do |key|
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.encoding = 'utf-8'
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
@@ -1,3 +1,3 @@
1
1
  module FormRobot
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -5,8 +5,8 @@ describe Robot do
5
5
 
6
6
  it 'must give a UTF-8 response' do
7
7
  instructions = {
8
- go_to_url: 'http://www.google.com',
9
- enter_params: {
8
+ 'go_to_url' => 'http://www.google.com',
9
+ 'enter_params' => {
10
10
  'q' => 'broughton',
11
11
  },
12
12
  };
@@ -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: 'http://www.google.com',
9
- enter_params: {
8
+ 'go_to_url' => 'http://www.google.com',
9
+ 'enter_params' => {
10
10
  'q' => 'RubyGems',
11
11
  },
12
- look_for_text: 'rubygems.org',
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: 'http://www.linkedin.com/',
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: 'Republic of Ireland',
25
+ 'look_for_text' => 'Republic of Ireland',
26
26
  }, {
27
- go_to_url: 'https://github.com/',
28
- enter_params: {
27
+ 'go_to_url' => 'https://github.com/',
28
+ 'enter_params' => {
29
29
  'q' => 'mongoid',
30
30
  },
31
- look_for_text: 'Ruby ODM framework for MongoDB',
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.3
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