watir-rspec 2.0.1 → 2.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: 4c93cfce42f3922548d20d13cb93232cdc6dad73
4
- data.tar.gz: 9e0e2bd728c501cfc68292485c5a3211b9420b59
3
+ metadata.gz: 3fe29b37229f959db5b8b6b466d9e4fb7d88b5c8
4
+ data.tar.gz: 6a9a31c3b8df8a13e6754f5f0613f1f001911af5
5
5
  SHA512:
6
- metadata.gz: a428ec56427abb202f5b2670ec65c8dbc1d0d161e4528a9281a144be6b3ab73efa7343019c96fb72608cff40c8739f0dfc7d23f35e3c25e1ea0b45f5c9fe1dee
7
- data.tar.gz: 3a39c9439e98b0306740a30fcf6ee7803ed69e9dfe1e9bdba3995bafd333e007d9c3606c5eb27c44dcfb9d64c6ace204a184acd2e27f08c0daf2b3a20305595d
6
+ metadata.gz: 70f3fe05b402535b0a8d320af933537d785b2b625ebff64150d71f6afb2c0b09dd22d5e0fbf788a95b79032dd9291cab6e63dd2a39b8ddba2765fc43e26b9687
7
+ data.tar.gz: 55cd37ecf601751480795f34671511679a54d6bef57aa90f5f2f0bcaef54e928e4afb283906380992c90f7394278a5e7e0d518df6023e93ca5188b1b992b2942
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 2.0.2 - 2015/03/21
2
+
3
+ * Fix delegating methods to browser with blocks having parameters. Closes #12.
4
+
1
5
  ### 2.0.1 - 2015/03/18
2
6
 
3
7
  * Add license into gemspec (issue #6).
data/bin/watir-rspec CHANGED
File without changes
@@ -1,48 +1,49 @@
1
- require "forwardable"
2
-
3
- module Watir
4
- class RSpec
5
- module Helper
6
- extend Forwardable
7
-
8
- # @return [Watir::Browser] a current browser instance if it is initialized with
9
- # @browser or $browser variable name.
10
- def browser
11
- @browser || $browser
12
- end
13
-
14
- # Will dispatch all missing methods to the {#browser} instance.
15
- # @example Makes it possible to use Watir::Browser methods without specifying the browser instance in the specs like this:
16
- # it "should do something" do
17
- # # notice that we're calling Watir::Browser#text_field here directly
18
- # text_field(:id => "foo").should be_present
19
- # end
20
- def method_missing(name, *args)
21
- if browser.respond_to?(name)
22
- Helper.module_eval %Q[
23
- def #{name}(*args)
24
- if block_given?
25
- browser.send(:#{name}, *args) {yield}
26
- else
27
- browser.send(:#{name}, *args)
28
- end
29
- end
30
- ]
31
-
32
- if block_given?
33
- self.send(name, *args) {yield}
34
- else
35
- self.send(name, *args)
36
- end
37
- else
38
- super
39
- end
40
- end
41
-
42
- # make sure that using method 'p' will be invoked on browser
43
- # and not Kernel
44
- # use Kernel.p if you need to dump some variable
45
- def_delegators :browser, :p
46
- end
47
- end
48
- end
1
+ require "forwardable"
2
+
3
+ module Watir
4
+ class RSpec
5
+ module Helper
6
+ extend Forwardable
7
+
8
+ # @return [Watir::Browser] a current browser instance if it is initialized with
9
+ # @browser or $browser variable name.
10
+ def browser
11
+ @browser || $browser
12
+ end
13
+
14
+ # Will dispatch all missing methods to the {#browser} instance.
15
+ # @example Makes it possible to use Watir::Browser methods without specifying the browser instance in the specs like this:
16
+ # it "should do something" do
17
+ # # notice that we're calling Watir::Browser#text_field here directly
18
+ # text_field(:id => "foo").should be_present
19
+ # end
20
+ def method_missing(name, *args)
21
+ if browser.respond_to?(name)
22
+ Helper.module_eval %Q[
23
+ def #{name}(*args)
24
+ if block_given?
25
+ browser.send(:#{name}, *args, &Proc.new)
26
+ else
27
+ browser.send(:#{name}, *args)
28
+ end
29
+ end
30
+ ]
31
+
32
+ if block_given?
33
+ self.send(name, *args, &Proc.new)
34
+ else
35
+ self.send(name, *args)
36
+ end
37
+ else
38
+ super
39
+ end
40
+ end
41
+
42
+
43
+ # make sure that using method 'p' will be invoked on browser
44
+ # and not Kernel
45
+ # use Kernel.p if you need to dump some variable
46
+ def_delegators :browser, :p
47
+ end
48
+ end
49
+ end
@@ -1,5 +1,5 @@
1
1
  module Watir
2
2
  class RSpec
3
- VERSION = "2.0.1"
3
+ VERSION = "2.0.2"
4
4
  end
5
5
  end
@@ -1,56 +1,74 @@
1
- require "spec_helper"
2
-
3
- describe Watir::RSpec::Helper do
4
- before { self.send :extend, described_class }
5
- after { $browser = @browser = nil }
6
-
7
- context "#browser" do
8
- it "delegates to @browser if exists" do
9
- @browser = :browser
10
- expect(browser).to be @browser
11
- end
12
-
13
- it "delegates to @browser if @browser exists even if $browser exists" do
14
- @browser = :browser
15
- $browser = :global_browser
16
- expect(browser).to be @browser
17
- end
18
-
19
- it "delegates to $browser if @browser does not exist" do
20
- $browser = :global_browser
21
- expect(browser).to be $browser
22
- end
23
- end
24
-
25
- context "#method_missing" do
26
- it "redirects missing methods to browser if method exists" do
27
- @browser = double("browser", coolness_factor: :very)
28
- expect(coolness_factor).to eql :very
29
- end
30
-
31
- it "raises error when browser does not have method" do
32
- @browser = double("browser")
33
- expect(described_class).not_to be_method_defined :not_existing_method
34
-
35
- expect do
36
- self.not_existing_method
37
- end.to raise_error(NoMethodError)
38
- expect(described_class).not_to be_method_defined :not_existing_method
39
- end
40
-
41
- it "adds browser methods to the helper" do
42
- @browser = double("browser", method_to_be_defined: :done)
43
-
44
- expect(described_class).not_to be_method_defined :method_to_be_defined
45
- expect(method_to_be_defined).to eql :done
46
- expect(described_class).to be_method_defined :method_to_be_defined
47
- end
48
- end
49
-
50
- it "#p is delegated to the browser" do
51
- @browser = double("browser", p: "#p")
52
- expect(described_class).not_to receive(:method_missing)
53
-
54
- expect(p).to eql "#p"
55
- end
56
- end
1
+ require "spec_helper"
2
+
3
+ describe Watir::RSpec::Helper do
4
+ before { self.send :extend, described_class }
5
+ after { $browser = @browser = nil }
6
+
7
+ context "#browser" do
8
+ it "delegates to @browser if exists" do
9
+ @browser = :browser
10
+ expect(browser).to be @browser
11
+ end
12
+
13
+ it "delegates to @browser if @browser exists even if $browser exists" do
14
+ @browser = :browser
15
+ $browser = :global_browser
16
+ expect(browser).to be @browser
17
+ end
18
+
19
+ it "delegates to $browser if @browser does not exist" do
20
+ $browser = :global_browser
21
+ expect(browser).to be $browser
22
+ end
23
+
24
+ context "methods with block" do
25
+ before { @browser = double("browser") }
26
+
27
+ it "are delegated to browser" do
28
+ expect(@browser).to receive(:window).with(title: "my_window") { |&block| block.call }
29
+
30
+ block_parameter = lambda { "my block content" }
31
+ expect(window(title: "my_window", &block_parameter)).to be == "my block content"
32
+ end
33
+
34
+ it "having parameters are properly delegated to browser" do
35
+ expect(@browser).to receive(:window).with(:title => "my_window").and_yield("first", "second")
36
+
37
+ block_parameter = lambda { |parameter_1, parameter_2| [parameter_1, parameter_2] }
38
+ expect(window(title: "my_window", &block_parameter)).to be == ["first", "second"]
39
+ end
40
+ end
41
+ end
42
+
43
+ context "#method_missing" do
44
+ it "redirects missing methods to browser if method exists" do
45
+ @browser = double("browser", coolness_factor: :very)
46
+ expect(coolness_factor).to eql :very
47
+ end
48
+
49
+ it "raises error when browser does not have method" do
50
+ @browser = double("browser")
51
+ expect(described_class).not_to be_method_defined :not_existing_method
52
+
53
+ expect do
54
+ self.not_existing_method
55
+ end.to raise_error(NoMethodError)
56
+ expect(described_class).not_to be_method_defined :not_existing_method
57
+ end
58
+
59
+ it "adds browser methods to the helper" do
60
+ @browser = double("browser", method_to_be_defined: :done)
61
+
62
+ expect(described_class).not_to be_method_defined :method_to_be_defined
63
+ expect(method_to_be_defined).to eql :done
64
+ expect(described_class).to be_method_defined :method_to_be_defined
65
+ end
66
+ end
67
+
68
+ it "#p is delegated to the browser" do
69
+ @browser = double("browser", p: "#p")
70
+ expect(described_class).not_to receive(:method_missing)
71
+
72
+ expect(p).to eql "#p"
73
+ end
74
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watir-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jarmo Pertman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-18 00:00:00.000000000 Z
11
+ date: 2015-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  version: '0'
133
133
  requirements: []
134
134
  rubyforge_project:
135
- rubygems_version: 2.0.7
135
+ rubygems_version: 2.4.6
136
136
  signing_key:
137
137
  specification_version: 4
138
138
  summary: Use Watir with RSpec with ease.