selenium-more 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63ae75641b9efc300ba56fb3d72cecd2068d0ec6
4
- data.tar.gz: 2eaeed4faf822998b045979f90b6b59d2faebffa
3
+ metadata.gz: 430e38cc3db22c67bb1f5a90da710a3ddc8912df
4
+ data.tar.gz: a070b39f1307a447122ff77e23543a1eac61c393
5
5
  SHA512:
6
- metadata.gz: 966d307b497a283fa7f241b7ae90d196f8548c4fe6f2ff50e938c4e723739fefec4faa164589609b21f01f0bca559926f517b91027acab1535b95cbe75d71cb3
7
- data.tar.gz: fc643f7b390e63f4715ec0cfe14ce68cc5a269c67b688b6db0a7fa97f34d0894074d9a398d0a20343be5f94717fdcb679a3d3bcd6cf272400a3841fbf8fd20c4
6
+ metadata.gz: 90a0592166dfa8f6850894987faef78c8ec5322b694ea40fb3549cfd155e7fcb5357dfedb625ecf0ba5557c1004d49db81559dd9278584be580aa64343051062
7
+ data.tar.gz: 80464f2ff87df53202486101b6a79ba672e3e8c01d1f50d7438cda9d2a4b59687856f3286c928be434a6407723666c599a79842b6378b96fea31c576d42571c3
@@ -2,3 +2,4 @@
2
2
  rvm:
3
3
  - 2.0.0
4
4
  - 2.1.0
5
+ - 2.1.1
@@ -0,0 +1,6 @@
1
+ # 0.0.2
2
+ * ADD
3
+ * hook to instance
4
+ # 0.0.1
5
+ * ADD
6
+ * hook to class
data/README.md CHANGED
@@ -5,7 +5,7 @@ Selenium WebDriver utilities.
5
5
  ## Features
6
6
 
7
7
  * hook interface to selenium-webdriver
8
- * utilities for test
8
+ * utilities for test (not yet)
9
9
  * session management
10
10
  * implicit and explicit wait
11
11
  * retry
@@ -35,8 +35,8 @@ Sample Code:
35
35
  class Selenium::WebDriver::Driver
36
36
  include Selenium::More::Hooks
37
37
 
38
- hook :get, before: ->(driver) { puts driver.current_url }
39
- after: ->(driver, ret) { puts driver.currnent_url }
38
+ hook :get, before: ->(driver, url) { puts driver.current_url }
39
+ after: ->(driver, ret, url) { puts driver.current_url }
40
40
  end
41
41
 
42
42
  driver = Selenium::WebDriver.for :phantomjs
@@ -50,6 +50,20 @@ about:blank
50
50
  http://example.com/
51
51
  ```
52
52
 
53
+ You can also add hook to each instance of ::Selenium::WebDriver::Driver. It results the same with above.
54
+
55
+ ```ruby
56
+ class Selenium::WebDriver::Driver
57
+ include Selenium::More::Hooks
58
+ end
59
+
60
+ driver = Selenium::WebDriver.for :phantomjs
61
+ driver.hook :get, before: ->(driver, url) { puts driver.current_url }
62
+ after: ->(driver, ret, url) { puts driver.current_url }
63
+
64
+ driver.get "http://example.com/"
65
+ ```
66
+
53
67
  ### session management
54
68
 
55
69
  T.B.D.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -6,22 +6,35 @@ module Selenium::More
6
6
  base.extend(ClassMethods)
7
7
  end
8
8
 
9
- module ClassMethods
10
- def hook(method, opts)
11
- if instance_methods.include?(method.to_sym)
12
- mod = Module.new do
13
- define_method method do |*args|
14
- opts[:before].call(self) if opts[:before]
15
- ret = super(*args)
16
- opts[:after].call(self, ret) if opts[:after]
9
+ def self.module_to_prepend(method_name, before: nil, after: nil)
10
+ raise ArgumentError, "at least one of before or after is needed" unless before || after
11
+
12
+ Module.new do
13
+ define_method method_name do |*args|
14
+ before.call(self, *args) if before
15
+ ret = super(*args)
16
+ after.call(self, ret, *args) if after
17
17
 
18
- ret
19
- end
20
- end
18
+ ret
19
+ end
20
+ end
21
+ end
21
22
 
22
- prepend(mod)
23
+ def hook(method_name, opts)
24
+ if respond_to?(method_name.to_sym)
25
+ # when ruby < 2.1.0, prepend is private method
26
+ self.singleton_class.__send__(:prepend, Hooks.module_to_prepend(method_name, opts))
27
+ else
28
+ raise NoMethodError, "no #{method_name} to hook"
29
+ end
30
+ end
31
+
32
+ module ClassMethods
33
+ def hook(method_name, opts)
34
+ if instance_methods.include?(method_name.to_sym)
35
+ prepend Hooks.module_to_prepend(method_name, opts)
23
36
  else
24
- raise NoMethodError, "no #{method} to hook"
37
+ raise NoMethodError, "no #{method_name} to hook"
25
38
  end
26
39
  end
27
40
  end
@@ -28,11 +28,11 @@ _DESCRIPTION_
28
28
  spec.add_development_dependency "rake"
29
29
 
30
30
  # test
31
- spec.add_runtime_dependency "rspec", "~> 3.0.0.beta"
31
+ spec.add_development_dependency "rspec", "~> 3.0.0.beta"
32
32
 
33
33
  # to run selenium-standalone-server
34
- spec.add_runtime_dependency "selenium-connect"
34
+ spec.add_development_dependency "selenium-connect"
35
35
 
36
36
  # auto test
37
- spec.add_runtime_dependency "guard-rspec"
37
+ spec.add_development_dependency "guard-rspec"
38
38
  end
@@ -3,16 +3,21 @@ require "spec_helper"
3
3
  require "selenium/more/hooks"
4
4
 
5
5
  describe Selenium::WebDriver::Driver, "with", Selenium::More::Hooks do
6
+ let(:base_class) do
7
+ Class.new(described_class) do
8
+ include Selenium::More::Hooks
9
+
10
+ def spy
11
+ @spy ||= []
12
+ end
13
+ attr_writer :spy
14
+ end
15
+ end
16
+
6
17
  context ".hook" do
7
18
  context "of before and after" do
8
19
  let(:klass) do
9
- Class.new(described_class) do
10
- include Selenium::More::Hooks
11
-
12
- def spy
13
- @spy ||= []
14
- end
15
-
20
+ Class.new(base_class) do
16
21
  hook :current_url, before: ->(driver) { driver.spy << "before_hook1" },
17
22
  after: ->(driver, ret) { driver.spy << "after_hook1" }
18
23
  hook :current_url, before: ->(driver) { driver.spy << "before_hook2" },
@@ -32,13 +37,23 @@ describe Selenium::WebDriver::Driver, "with", Selenium::More::Hooks do
32
37
  end
33
38
  end
34
39
 
35
- context "of after" do
40
+ context "of before" do
36
41
  let(:klass) do
37
- Class.new(described_class) do
38
- include Selenium::More::Hooks
42
+ Class.new(base_class) do
43
+ hook :get, before: ->(driver, url) { driver.spy = url }
44
+ end
45
+ end
39
46
 
40
- attr_accessor :spy
47
+ let(:driver) { klass.for :remote, desired_capabilities: :htmlunit }
41
48
 
49
+ it "passes args to before hook" do
50
+ expect { driver.get "about:blank" }.to change { driver.spy }.to("about:blank")
51
+ end
52
+ end
53
+
54
+ context "of after" do
55
+ let(:klass) do
56
+ Class.new(base_class) do
42
57
  hook :current_url, after: ->(driver, ret) { driver.spy = ret }
43
58
  end
44
59
  end
@@ -54,13 +69,62 @@ describe Selenium::WebDriver::Driver, "with", Selenium::More::Hooks do
54
69
  context "when no method is available" do
55
70
  it "raise NoMethodError" do
56
71
  expect {
57
- Class.new(described_class) do
58
- include Selenium::More::Hooks
59
-
72
+ Class.new(base_class) do
60
73
  hook :hoge, before: ->(driver) { driver }
61
74
  end
62
75
  }.to raise_exception(NoMethodError, "no hoge to hook")
63
76
  end
64
77
  end
65
78
  end
79
+
80
+ context "#hook" do
81
+ context "of before and after" do
82
+ let(:klass) { base_class }
83
+
84
+ let(:driver) do
85
+ driver = klass.for :remote, desired_capabilities: :htmlunit
86
+ driver.hook :current_url, before: ->(driver) { driver.spy << "before_hook1" },
87
+ after: ->(driver, ret) { driver.spy << "after_hook1" }
88
+ driver.hook :current_url, before: ->(driver) { driver.spy << "before_hook2" },
89
+ after: ->(driver, ret) { driver.spy << "after_hook2" }
90
+ driver
91
+ end
92
+
93
+ it "is called before and after in order" do
94
+ expect { driver.current_url }.to change { driver.spy }.to(%w[ before_hook2 before_hook1 after_hook1 after_hook2 ])
95
+ end
96
+ end
97
+
98
+ context "when no method is available" do
99
+ let(:klass) { base_class }
100
+
101
+ let(:driver) { base_class.for :remote, desired_capabilities: :htmlunit }
102
+
103
+ it "raise NoMethodError" do
104
+ expect {
105
+ driver.hook :hoge, before: ->(driver) { driver }
106
+ }.to raise_exception(NoMethodError, "no hoge to hook")
107
+ end
108
+ end
109
+ end
110
+
111
+ context "convination with .hook and #hook" do
112
+ let(:klass) do
113
+ Class.new(base_class) do
114
+ hook :current_url, before: ->(driver) { driver.spy << "before_hook1" },
115
+ after: ->(driver, ret) { driver.spy << "after_hook1" }
116
+ end
117
+ end
118
+
119
+ let(:driver) do
120
+ driver = klass.for :remote, desired_capabilities: :htmlunit
121
+ driver.hook :current_url, before: ->(driver) { driver.spy << "before_hook2" },
122
+ after: ->(driver, ret) { driver.spy << "after_hook2" }
123
+ driver
124
+ end
125
+
126
+ it "is called before and after in order" do
127
+ expect { driver.current_url }.to change { driver.spy }.to(%w[ before_hook2 before_hook1 after_hook1 after_hook2 ])
128
+ end
129
+ end
66
130
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selenium-more
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - okitan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-02 00:00:00.000000000 Z
11
+ date: 2014-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: selenium-webdriver
@@ -59,7 +59,7 @@ dependencies:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: 3.0.0.beta
62
- type: :runtime
62
+ type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
@@ -73,7 +73,7 @@ dependencies:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
- type: :runtime
76
+ type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
@@ -87,7 +87,7 @@ dependencies:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
- type: :runtime
90
+ type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
@@ -108,6 +108,7 @@ extra_rdoc_files: []
108
108
  files:
109
109
  - ".gitignore"
110
110
  - ".travis.yml"
111
+ - CHANGELOG.md
111
112
  - Gemfile
112
113
  - Guardfile
113
114
  - LICENSE.txt