capy 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -31,6 +31,14 @@ Change the browser:
31
31
 
32
32
  $ capy -b firefox example.capy
33
33
 
34
+ Using the webkit:
35
+
36
+ $ gem install capybara-webkit
37
+
38
+ and capy with '-w' option
39
+
40
+ $ capy -w example.capy
41
+
34
42
  ### JavaScript Mode
35
43
 
36
44
  # example.js
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env capy
2
2
 
3
- visit 'http://google.com/'
3
+ visit 'http://google.co.jp/'
4
4
  fill_in 'q', :with => 'ruby'
5
- page.evaluate_script("document.forms[0].submit()")
5
+ js 'document.forms[0].submit()'
6
+ puts js('document.getElementsByName("q")[0].value + "の検索結果: " + document.getElementById("resultStats").textContent')
data/lib/capy.rb CHANGED
@@ -15,21 +15,19 @@ module Capy
15
15
  on :j, :js, 'eval script as javascript with -a option'
16
16
  on :a, :'app-host=', 'app host'
17
17
  on :s, :'stop', 'stop after eval script'
18
+ on :w, :webkit, 'use capybara webkit'
18
19
  end
19
20
  return 1 if opts.help?
20
21
 
21
22
  trap('INT') { exit }
22
23
 
23
- Capybara.register_driver :selenium do |app|
24
- Capybara::Selenium::Driver.new(app, :browser => opts[:browser].to_sym)
25
- end
26
- Capybara.current_driver = :selenium
27
- Capybara.app_host = opts[:'app-host']
24
+ setup_capybara
28
25
 
29
26
  @mode = opts.js? ? :javascript : :capybara
30
27
 
31
28
  evaluater = Evaluater.new
32
- evaluater.visit (Capybara.app_host) if Capybara.app_host
29
+
30
+ evaluater.visit Capybara.app_host if Capybara.app_host
33
31
 
34
32
  if args.empty?
35
33
  start_shell evaluater
@@ -40,7 +38,8 @@ module Capy
40
38
  return 1
41
39
  end
42
40
  puts "Running: #{script_file} ..."
43
- evaluater.eval_script File.read(script_file), mode
41
+ result = evaluater.eval_script File.read(script_file), mode
42
+ puts "=> #{result.inspect}".cyan
44
43
  start_shell evaluater if opts.stop?
45
44
  end
46
45
  end
@@ -54,6 +53,22 @@ module Capy
54
53
  1
55
54
  end
56
55
 
56
+ def setup_capybara
57
+ if opts.webkit?
58
+ require 'capybara-webkit'
59
+ Capybara.register_driver :webkit do |app|
60
+ Capybara::Driver::Webkit.new(app, :browser => Capybara::Driver::Webkit::Browser.new)
61
+ end
62
+ Capybara.current_driver = :webkit
63
+ else
64
+ Capybara.register_driver :selenium do |app|
65
+ Capybara::Selenium::Driver.new(app, :browser => opts[:browser].to_sym)
66
+ end
67
+ Capybara.current_driver = :selenium
68
+ end
69
+ Capybara.app_host = opts[:'app-host']
70
+ end
71
+
57
72
  EXIT_COMMANDS = %w(exit quit)
58
73
 
59
74
  def start_shell(evaluater)
@@ -108,6 +123,15 @@ module Capy
108
123
  class Evaluater
109
124
  include Capybara::DSL
110
125
 
126
+ def initialize
127
+ if page.driver.respond_to?(:header)
128
+ page.driver.header(
129
+ 'user-agent',
130
+ 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/534.55.3 (KHTML, like Gecko) Version/5.1.5 Safari/534.55.3'
131
+ )
132
+ end
133
+ end
134
+
111
135
  def eval_script(script, mode)
112
136
  case mode
113
137
  when :javascript
data/lib/capy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Capy
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
metadata CHANGED
@@ -1,79 +1,104 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: capy
3
- version: !ruby/object:Gem::Version
4
- version: 1.3.0
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ hash: 7
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 4
9
+ - 0
10
+ version: 1.4.0
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - jugyo
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-04-24 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2012-04-24 00:00:00 +09:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
15
22
  name: slop
16
- requirement: &70160342289140 !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
17
25
  none: false
18
- requirements:
26
+ requirements:
19
27
  - - ~>
20
- - !ruby/object:Gem::Version
21
- version: '3.1'
28
+ - !ruby/object:Gem::Version
29
+ hash: 5
30
+ segments:
31
+ - 3
32
+ - 1
33
+ version: "3.1"
22
34
  type: :runtime
23
- prerelease: false
24
- version_requirements: *70160342289140
25
- - !ruby/object:Gem::Dependency
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
26
37
  name: capybara
27
- requirement: &70160342288100 !ruby/object:Gem::Requirement
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
28
40
  none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
33
48
  type: :runtime
34
- prerelease: false
35
- version_requirements: *70160342288100
36
- - !ruby/object:Gem::Dependency
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
37
51
  name: colored
38
- requirement: &70160342287140 !ruby/object:Gem::Requirement
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
39
54
  none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
43
- version: '0'
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
44
62
  type: :runtime
45
- prerelease: false
46
- version_requirements: *70160342287140
47
- - !ruby/object:Gem::Dependency
63
+ version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
48
65
  name: rspec
49
- requirement: &70160342286280 !ruby/object:Gem::Requirement
66
+ prerelease: false
67
+ requirement: &id004 !ruby/object:Gem::Requirement
50
68
  none: false
51
- requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
55
76
  type: :development
56
- prerelease: false
57
- version_requirements: *70160342286280
58
- - !ruby/object:Gem::Dependency
77
+ version_requirements: *id004
78
+ - !ruby/object:Gem::Dependency
59
79
  name: rr
60
- requirement: &70160342281840 !ruby/object:Gem::Requirement
80
+ prerelease: false
81
+ requirement: &id005 !ruby/object:Gem::Requirement
61
82
  none: false
62
- requirements:
63
- - - ! '>='
64
- - !ruby/object:Gem::Version
65
- version: '0'
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
66
90
  type: :development
67
- prerelease: false
68
- version_requirements: *70160342281840
91
+ version_requirements: *id005
69
92
  description: Capybara Script Runner
70
- email:
93
+ email:
71
94
  - jugyo.org@gmail.com
72
- executables:
95
+ executables:
73
96
  - capy
74
97
  extensions: []
98
+
75
99
  extra_rdoc_files: []
76
- files:
100
+
101
+ files:
77
102
  - .gitignore
78
103
  - Gemfile
79
104
  - LICENSE
@@ -90,31 +115,41 @@ files:
90
115
  - spec/fixtures/foo.capy
91
116
  - spec/fixtures/foo.js
92
117
  - spec/spec_helper.rb
118
+ has_rdoc: true
93
119
  homepage: https://github.com/jugyo
94
120
  licenses: []
121
+
95
122
  post_install_message:
96
123
  rdoc_options: []
97
- require_paths:
124
+
125
+ require_paths:
98
126
  - lib
99
- required_ruby_version: !ruby/object:Gem::Requirement
127
+ required_ruby_version: !ruby/object:Gem::Requirement
100
128
  none: false
101
- requirements:
102
- - - ! '>='
103
- - !ruby/object:Gem::Version
104
- version: '0'
105
- required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ hash: 3
133
+ segments:
134
+ - 0
135
+ version: "0"
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
137
  none: false
107
- requirements:
108
- - - ! '>='
109
- - !ruby/object:Gem::Version
110
- version: '0'
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ hash: 3
142
+ segments:
143
+ - 0
144
+ version: "0"
111
145
  requirements: []
146
+
112
147
  rubyforge_project:
113
- rubygems_version: 1.8.10
148
+ rubygems_version: 1.3.7
114
149
  signing_key:
115
150
  specification_version: 3
116
151
  summary: The capy command to run the script written in Capybara DSL.
117
- test_files:
152
+ test_files:
118
153
  - spec/capy_spec.rb
119
154
  - spec/fixtures/foo.capy
120
155
  - spec/fixtures/foo.js