watir-rspec 0.0.3 → 1.0.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bbbc8f72cbcb8c30d1ae8d802de384282a811d42
4
+ data.tar.gz: 1b4866fceef13da65071c510b0363b26851599f6
5
+ SHA512:
6
+ metadata.gz: 586f19b53415d428a7261704d4e4d8932dc7fe1c91ecdde8029a2402e0cfcce22218e928aa59a2ecf23dcc793ce6be506faad23d2293486b8fa19b5596f20199
7
+ data.tar.gz: 7ab92d211d77365d18218a8be6fd73cbf8663e3f1b103497ed9dd518aab0e89eea4ecc8ded1175ae58d9602b250c7570ffddabf39e9f33bcb85bcd0ec66faed5
@@ -0,0 +1,11 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - ruby-head
5
+ notifications:
6
+ recipients:
7
+ - jarmo.p@gmail.com
8
+ matrix:
9
+ allow_failures:
10
+ - rvm: ruby-head
11
+
data/CHANGES ADDED
@@ -0,0 +1,5 @@
1
+ # 1.0.0 - 2013/09/21
2
+
3
+ * add installation binary watir-rspec for easier installation of the gem
4
+ * many internal changes
5
+ * README revamp
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ gem 'coveralls', require: false
data/README.md CHANGED
@@ -1,7 +1,16 @@
1
1
  # Watir::RSpec
2
+ [![Gem Version](https://badge.fury.io/rb/test-page.png)](http://badge.fury.io/rb/watir-rspec)
3
+ [![Build Status](https://api.travis-ci.org/watir/watir-rspec.png)](http://travis-ci.org/watir/watir-rspec)
4
+ [![Coverage](https://coveralls.io/repos/watir/watir-rspec/badge.png?branch=master)](https://coveralls.io/r/watir/watir-rspec)
2
5
 
3
6
  Use [Watir](http://watir.com) with [RSpec](http://rspec.info) with ease.
4
7
 
8
+ * No need to use the `@browser` or `$browser` variables when executing browser methods.
9
+ * No need to open the browser in your each test manually.
10
+ * Easily test for asynchronous events by using `#within` matchers.
11
+ * Easily test that something stays the same within some period by using `#during` matchers.
12
+ * Get nice html reports with links to html, screenshots and other files generated during test.
13
+
5
14
  ## Installation
6
15
 
7
16
  Add these lines to your application's Gemfile:
@@ -12,128 +21,54 @@ group :test do
12
21
  end
13
22
  ````
14
23
 
15
- And add these lines to your spec\_helper.rb file:
16
-
17
- ````ruby
18
- RSpec.configure do |config|
19
- # Add Watir::RSpec::HtmlFormatter to get links to the screenshots, html and
20
- # all other files created during the failing examples.
21
- config.add_formatter('documentation')
22
- config.add_formatter(Watir::RSpec::HtmlFormatter)
23
-
24
- # Open up the browser for each example.
25
- config.before :all do
26
- @browser = Watir::Browser.new
27
- end
28
-
29
- # Close that browser after each example.
30
- config.after :all do
31
- @browser.close if @browser
32
- end
33
-
34
- # Include RSpec::Helper into each of your example group for making it possible to
35
- # write in your examples instead of:
36
- # @browser.goto "localhost"
37
- # @browser.text_field(:name => "first_name").set "Bob"
38
- #
39
- # like this:
40
- # goto "localhost"
41
- # text_field(:name => "first_name").set "Bob"
42
- #
43
- # This needs that you've used @browser as an instance variable name in
44
- # before :all block.
45
- config.include Watir::RSpec::Helper
46
- end
47
- ````
48
-
49
-
50
- When using Rails and writing specs to requests directory, add an additional filter for RSpec:
24
+ Or install it manually as:
51
25
 
52
- ````ruby
53
- config.before :all, :type => :request do
54
- @browser = Watir::Browser.new :chrome
55
- end
26
+ gem install watir-rspec
56
27
 
57
- config.after :all, :type => :request do
58
- @browser.close if @browser
59
- end
28
+ And execute the following command to add `watir-rspec` configuration into your `spec_helper`:
60
29
 
61
- config.include Watir::RSpec::Helper, :type => :request
62
- ````
30
+ watir-rspec install
63
31
 
64
32
  ## Usage
65
33
 
66
- ### Executing browser methods
67
-
68
- If you did include ````Watir::Rspec::Helper```` then it is possible to write code like this in your specs:
69
-
70
- ````ruby
71
- text_field(:id => "something").set "foo"
72
- ````
73
-
74
- If you did not include ````Watir::RSpec::Helper```` then you have to use browser variable:
75
-
76
- ````ruby
77
- @browser.text_field(:id => "something").set "foo"
78
- ````
79
-
80
- ### Testing asynchronous functionality
81
-
82
- ````Watir::RSpec```` adds convenience methods ````#within```` and ````#during```` to all of the RSpec matchers,
83
- which help to write better and more beautiful test code.
84
-
85
- Let us pretend that the following div will appear dynamically after some Ajax request.
86
-
87
- We can use the standard way:
34
+ Check out the [documentation](http://rubydoc.info/gems/watir-rspec/frames) and the straight-forward fully working examples below.
88
35
 
89
36
  ````ruby
90
- Watir::Wait.until(5) { div(:id => "something").present? }
91
- ````
92
-
93
- Or we can use ````#within```` method:
94
-
95
- ````ruby
96
- div(:id => "something").should be_present.within(5)
97
- ````
98
-
99
- ````#during```` is the opposite of ````#within```` - it means that during the specified time something should be true/false.
37
+ require "spec_helper"
100
38
 
101
- PS! There is one caveat when using ````#within```` or ````#during```` - it cannot be used in every possible situation.
102
-
103
- For example, this won't work as expected:
104
-
105
- ````ruby
106
- div(:id => "something").text.should eq("foo").within(5)
39
+ describe "Google" do
40
+ before { goto "http://google.com" }
41
+
42
+ it "has search box" do
43
+ text_field(:name => "q").should be_present
44
+ end
45
+
46
+ it "allows to search" do
47
+ text_field(:name => "q").set "watir"
48
+ button(:id => "gbqfb").click
49
+ results = div(:id => "ires")
50
+ results.should be_present.within(2)
51
+ results.lis(:class => "g").map(&:text).should be_any { |text| text =~ /watir/ }
52
+ results.should be_present.during(1)
53
+ end
54
+ end
107
55
  ````
108
56
 
109
- The reason is that RSpec will check if value of ````#text```` will change to ````"foo"````, but it is just some ````String````,
110
- which won't change ever. The rule of thumb is that ````#should```` should be always called on an instance of
111
- the ````Element```` and ````#within/#duration```` on the matcher for that ````Element```` (e.g. ````be_present````, ````be_visible````, ````exist```` etc.).
112
-
113
57
  ### Files created during specs
114
58
 
115
- When creating/downloading/uploading files in your examples and using
116
- ````Watir::RSpec::HtmlFormatter```` then you can generate links automatically to these files when example
117
- fails. To do that you need to use ````Watir::RSpec.file_path```` method for generating
118
- unique file name:
59
+ You can use `Watir::RSpec.file_path` to have links automatically in the html report
60
+ to the files created during tests.
119
61
 
120
- ````ruby
62
+ ```ruby
121
63
  uploaded_file_path = Watir::RSpec.file_path("uploaded.txt")
122
64
  File.open(uploaded_file_path, "w") {|file| file.write "Generated File Input"}
123
- ````
124
-
125
- ### Rails support
126
-
127
- If you're using Rails, then you also need to install [watir-rails](https://github.com/watir/watir-rails) gem.
65
+ file_field(:name => "upload-file").set uploaded_file_path
66
+ ```
128
67
 
129
- ## Contributing
68
+ ### Rails
130
69
 
131
- 1. Fork it
132
- 2. Create your feature branch (`git checkout -b my-new-feature`)
133
- 3. Commit your changes (`git commit -am 'Added some feature'`)
134
- 4. Push to the branch (`git push origin my-new-feature`)
135
- 5. Create new Pull Request
70
+ You need to use [rspec-rails](https://github.com/rspec/rspec-rails) and [watir-rails](https://github.com/watir/watir-rails) gems together with `watir-rspec` to achieve maximum satisfaction.
136
71
 
137
72
  ## License
138
73
 
139
- Copyright (c) Jarmo Pertman (jarmo.p@gmail.com). See LICENSE for details.
74
+ Copyright (c) [Jarmo Pertman](https://github.com/jarmo) (jarmo.p@gmail.com). See LICENSE for details.
data/Rakefile CHANGED
@@ -1,4 +1,10 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+ task :release => :spec
8
+
3
9
  require "yard"
4
10
  YARD::Rake::YardocTask.new
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "watir/rspec/cli"
4
+ Watir::RSpec::CLI.execute
5
+
@@ -1,110 +1,11 @@
1
- require 'rspec'
2
- require File.expand_path("rspec/helper", File.dirname(__FILE__))
3
- require File.expand_path("rspec/html_formatter", File.dirname(__FILE__))
4
-
5
- if defined? ActiveRecord
6
- require File.expand_path("rspec/active_record_shared_connection", File.dirname(__FILE__))
7
- end
8
-
9
1
  module Watir
10
2
  class RSpec
11
3
  class << self
12
- # Add #within(timeout) and #during(timeout) methods for every matcher for allowing to wait until some condition is met.
13
- # div.click
14
- # another_div.should be_present.within(5)
15
- #
16
- # expect {
17
- # div.click
18
- # }.to change {another_div.text}.from("before").to("after").within(5)
19
- #
20
- # expect {
21
- # div.click
22
- # }.to make {another_div.present?}.within(5)
23
- #
24
- # expect {
25
- # div.click
26
- # }.to change {another_div.text}.soon
27
- #
28
- # @private
29
- def add_within_and_during_to_matcher const
30
- const.class_eval do
31
-
32
- inst_methods = instance_methods.map &:to_sym
33
-
34
- if !(inst_methods.include?(:__matches?) || inst_methods.include?(:__does_not_match?)) &&
35
- (inst_methods.include?(:matches?) || inst_methods.include?(:does_not_match?))
36
-
37
- def within(timeout)
38
- @within_timeout = timeout
39
- self
40
- end
41
-
42
- def during(timeout)
43
- @during_timeout = timeout
44
- self
45
- end
46
-
47
- def soon
48
- within(30)
49
- end
50
-
51
- def seconds
52
- # for syntactic sugar
53
- self
54
- end
55
-
56
- alias_method :second, :seconds
57
-
58
- def minutes
59
- @within_timeout *= 60 if @within_timeout
60
- @during_timeout *= 60 if @during_timeout
61
- self
62
- end
63
-
64
- alias_method :minute, :minutes
65
- end
66
-
67
- if inst_methods.include? :matches?
68
- alias_method :__matches?, :matches?
69
-
70
- def matches?(actual)
71
- match_with_wait {__matches?(actual)}
72
- end
73
- end
74
-
75
- if inst_methods.include? :does_not_match?
76
- alias_method :__does_not_match?, :does_not_match?
77
-
78
- def does_not_match?(actual)
79
- match_with_wait {__does_not_match?(actual)}
80
- end
81
- elsif inst_methods.include? :matches?
82
- def does_not_match?(actual)
83
- match_with_wait {!__matches?(actual)}
84
- end
85
- end
86
-
87
- private
88
-
89
- def match_with_wait
90
- if @within_timeout
91
- timeout = @within_timeout; @within_timeout = nil
92
- Watir::Wait.until(timeout) {yield} rescue false
93
- elsif @during_timeout
94
- timeout = @during_timeout; @during_timeout = nil
95
- Watir::Wait.while(timeout) {yield} rescue true
96
- else
97
- yield
98
- end
99
- end
100
- end
101
- end
102
-
103
4
  # Generate unique file path for the current spec. If the file
104
5
  # will be created during that spec and spec fails then it will be
105
6
  # shown automatically in the html report.
106
7
  #
107
- # @param [String] File name to be used for file.
8
+ # @param [String] file_name File name to be used for file.
108
9
  # Will be used as a part of the complete name.
109
10
  # @return [String] Absolute path for the unique file name.
110
11
  # @raise [RuntimeError] when {Watir::RSpec::HtmlFormatter} is not in use.
@@ -112,6 +13,11 @@ module Watir
112
13
  formatter.file_path(file_name, description=nil)
113
14
  end
114
15
 
16
+ # @private
17
+ def active_record_loaded?
18
+ defined? ActiveRecord::Base
19
+ end
20
+
115
21
  private
116
22
 
117
23
  def formatter
@@ -131,38 +37,15 @@ module Watir
131
37
  formatter
132
38
  end
133
39
  end
134
-
135
-
136
40
  end
137
-
138
41
  end
139
42
  end
140
43
 
141
- # patch for #within(timeout) method
142
- # @private
143
- module ::RSpec::Matchers
144
- class BuiltIn::Change
145
- def matches?(event_proc)
146
- raise_block_syntax_error if block_given?
44
+ require "rspec"
147
45
 
148
- # to make #change work with #in(timeout) method
149
- unless defined? @actual_before
150
- @actual_before = evaluate_value_proc
151
- event_proc.call
152
- end
153
- @actual_after = evaluate_value_proc
154
-
155
- (!change_expected? || changed?) && matches_before? && matches_after? && matches_expected_delta? && matches_min? && matches_max?
156
- end
157
- end
158
-
159
- alias_method :make, :change
160
- end
161
-
162
- matchers = RSpec::Matchers::BuiltIn.constants.map(&:to_sym)
163
- matchers.delete :BaseMatcher
164
- matchers.each do |const|
165
- Watir::RSpec.add_within_and_during_to_matcher RSpec::Matchers::BuiltIn.const_get const
166
- end
46
+ require File.expand_path("rspec/active_record_shared_connection", File.dirname(__FILE__))
47
+ require File.expand_path("rspec/helper", File.dirname(__FILE__))
48
+ require File.expand_path("rspec/matchers/base_matcher", File.dirname(__FILE__))
49
+ require File.expand_path("rspec/matchers", File.dirname(__FILE__))
50
+ require File.expand_path("rspec/html_formatter", File.dirname(__FILE__))
167
51
 
168
- Watir::RSpec.add_within_and_during_to_matcher RSpec::Matchers::DSL::Matcher
@@ -1,16 +1,20 @@
1
- RSpec.configuration.before(:suite) do
2
- # Allow RSpec specs to use transactional fixtures when using Watir.
3
- #
4
- # Tip from http://blog.plataformatec.com.br/2011/12/three-tips-to-improve-the-performance-of-your-test-suite/
5
- class ::ActiveRecord::Base
6
- mattr_accessor :shared_connection
7
- @@shared_connection = nil
1
+ if Watir::RSpec.active_record_loaded?
2
+ require "thread"
8
3
 
9
- def self.connection
10
- @@shared_connection || retrieve_connection
4
+ RSpec.configuration.before(:suite) do
5
+ # Allow RSpec specs to use transactional fixtures when using Watir.
6
+ #
7
+ # Tip from http://blog.plataformatec.com.br/2011/12/three-tips-to-improve-the-performance-of-your-test-suite/
8
+ class ::ActiveRecord::Base
9
+ @shared_connection_semaphore = Mutex.new
10
+
11
+ class << self
12
+ def connection
13
+ @shared_connection_semaphore.synchronize do
14
+ @shared_connection ||= retrieve_connection
15
+ end
16
+ end
17
+ end
11
18
  end
12
19
  end
13
-
14
- # Forces all threads to share the same connection.
15
- ::ActiveRecord::Base.shared_connection = ::ActiveRecord::Base.connection
16
20
  end
@@ -0,0 +1,125 @@
1
+ require "optparse"
2
+
3
+ module Watir
4
+ class RSpec
5
+ # @private
6
+ class CLI
7
+ class << self
8
+ def execute
9
+ @options = {}
10
+ parser = OptionParser.new do |opts|
11
+ opts.banner = "Install watir-rspec configuration into spec_helper file.
12
+
13
+ Usage: watir-rspec [options] install"
14
+
15
+ opts.on("-r", "--[no-]rails", "Force to install watir-rspec for Rails application if the detection fails") do |v|
16
+ @options[:rails] = v
17
+ end
18
+ end
19
+
20
+ parser.parse!
21
+
22
+ if ARGV.size != 1 || ARGV.first != "install"
23
+ puts parser
24
+ exit
25
+ end
26
+
27
+ unless already_installed?
28
+ install
29
+ else
30
+ puts "watir-rspec is already installed into #{spec_helper}... skipping."
31
+ exit
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def install
38
+ puts "Rails application #{using_rails? ? "detected" : "not detected"}.
39
+ Installing watir-rspec configuration into #{spec_helper}."
40
+
41
+ File.open(spec_helper, "a") do |file|
42
+ file.puts %Q[
43
+ # Configuration for watir-rspec
44
+ require "watir/rspec"
45
+
46
+ RSpec.configure do |config|
47
+ # Use Watir::RSpec::HtmlFormatter to get links to the screenshots, html and
48
+ # all other files created during the failing examples.
49
+ config.add_formatter(:progress) if config.formatters.empty?
50
+ config.add_formatter(Watir::RSpec::HtmlFormatter)
51
+
52
+ # Open up the browser for each example.
53
+ config.before :all#{rails_filter} do
54
+ @browser = Watir::Browser.new
55
+ end
56
+
57
+ # Close that browser after each example.
58
+ config.after :all#{rails_filter} do
59
+ @browser.close if @browser
60
+ end
61
+
62
+ # Include RSpec::Helper into each of your example group for making it possible to
63
+ # write in your examples instead of:
64
+ # @browser.goto "localhost"
65
+ # @browser.text_field(:name => "first_name").set "Bob"
66
+ #
67
+ # like this:
68
+ # goto "localhost"
69
+ # text_field(:name => "first_name").set "Bob"
70
+ #
71
+ # This needs that you've used @browser as an instance variable name in
72
+ # before :all block.
73
+ config.include Watir::RSpec::Helper#{rails_filter}
74
+
75
+ # Include RSpec::Matchers into each of your example group for making it possible to
76
+ # use #within with some of RSpec matchers for easier asynchronous testing:
77
+ # @browser.text_field(:name => "first_name").should exist.within(2)
78
+ # @browser.text_field(:name => "first_name").should be_present.within(2)
79
+ # @browser.text_field(:name => "first_name").should be_visible.within(2)
80
+ #
81
+ # You can also use #during to test if something stays the same during the specified period:
82
+ # @browser.text_field(:name => "first_name").should exist.during(2)
83
+ config.include Watir::RSpec::Matchers#{rails_filter}
84
+ end
85
+ ]
86
+ end
87
+ end
88
+
89
+ def already_installed?
90
+ File.exist?(spec_helper) && File.read(spec_helper) =~ /Watir::RSpec/
91
+ end
92
+
93
+ def spec_directory
94
+ specs = File.expand_path("spec")
95
+
96
+ unless File.directory? specs
97
+ puts %Q[#{specs} directory not found.
98
+ Make sure you run the watir-rspec command within your projects' directory.]
99
+
100
+ exit 1
101
+ end
102
+
103
+ specs
104
+ end
105
+
106
+ def spec_helper
107
+ File.join(spec_directory, "spec_helper.rb")
108
+ end
109
+
110
+ def rails_filter
111
+ ", :type => :request" if using_rails?
112
+ end
113
+
114
+ def using_rails?
115
+ return @options[:rails] if @options.has_key? :rails
116
+
117
+ @using_rails ||= begin
118
+ File.exists?("Gemfile.lock") && File.read("Gemfile.lock") =~ /rspec-rails/ ||
119
+ File.exists?("Gemfile") && File.read("Gemfile") =~ /rspec-rails/
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
@@ -3,7 +3,7 @@ module Watir
3
3
  module Helper
4
4
  extend Forwardable
5
5
 
6
- # @return [Watir::Browser] a latest browser instance if it is initialized with
6
+ # @return [Watir::Browser] a current browser instance if it is initialized with
7
7
  # @browser or $browser variable name.
8
8
  def browser
9
9
  @browser || $browser
@@ -55,7 +55,7 @@ module Watir
55
55
  # will be created during that spec and spec fails then it will be
56
56
  # shown automatically in the html report.
57
57
  #
58
- # @param [String] File name to be used for file.
58
+ # @param [String] file_name File name to be used for file.
59
59
  # Will be used as a part of the complete name.
60
60
  # @return [String] Absolute path for the unique file name.
61
61
  def file_path(file_name, description=nil)
@@ -0,0 +1,38 @@
1
+ module Watir
2
+ class RSpec
3
+ # All matchers defined in here have the ability to be used for asynchronous
4
+ # testing.
5
+ #
6
+ # There is #within matcher which means that the expected result should happen
7
+ # within the specified time period.
8
+ #
9
+ # There also exists less used #during matcher which means that the expected
10
+ # result should be true for the whole specified time period.
11
+ #
12
+ # @example Wait for 2 seconds until element is present (element exists and is visible)
13
+ # text_field.should be_present.within(2)
14
+ #
15
+ # @example Wait for 2 seconds until element is visible
16
+ # text_field.should be_visible.within(2)
17
+ #
18
+ # @example Wait for 2 seconds until element exists
19
+ # text_field.should exist.within(2)
20
+ #
21
+ # @example Make sure that container is visible for the whole time during 2 seconds
22
+ # button.click
23
+ # div.should be_visible.during(2)
24
+ module Matchers
25
+ def be_present
26
+ BaseMatcher.new :present?
27
+ end
28
+
29
+ def be_visible
30
+ BaseMatcher.new :visible?
31
+ end
32
+
33
+ def exist
34
+ BaseMatcher.new :exist?
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,76 @@
1
+ require "timeout"
2
+
3
+ module Watir
4
+ class RSpec
5
+ module Matchers
6
+ # @private
7
+ class BaseMatcher < ::RSpec::Matchers::BuiltIn::Be
8
+ def initialize(predicate)
9
+ @predicate = predicate
10
+ end
11
+
12
+ def matches?(target)
13
+ @target = target
14
+
15
+ if @within_seconds
16
+ match_with_timeout(@within_seconds, true) { target.send @predicate }
17
+ elsif @during_seconds
18
+ match_with_timeout(@during_seconds, false) { !target.send @predicate }
19
+ else
20
+ target.send(@predicate)
21
+ end
22
+ end
23
+
24
+ def does_not_match?(target)
25
+ @target = target
26
+
27
+ if @within_seconds
28
+ match_with_timeout(@within_seconds, true) { !target.send @predicate }
29
+ elsif @during_seconds
30
+ match_with_timeout(@during_seconds, false) { target.send @predicate }
31
+ else
32
+ !target.send(@predicate)
33
+ end
34
+ end
35
+
36
+ def failure_message_for_should
37
+ "expected #{@target.inspect} to #{be_prefix}#{@predicate.to_s[0..-2]}#{timeout_to_s}"
38
+ end
39
+
40
+ def failure_message_for_should_not
41
+ "expected #{@target.inspect} not to #{be_prefix}#{@predicate.to_s[0..-2]}#{timeout_to_s}"
42
+ end
43
+
44
+ def within(seconds)
45
+ @within_seconds = seconds
46
+ self
47
+ end
48
+
49
+ def during(seconds)
50
+ @during_seconds = seconds
51
+ self
52
+ end
53
+
54
+ private
55
+
56
+ def match_with_timeout(seconds, expected_result)
57
+ Timeout.timeout(seconds) { sleep 0.1 until (yield rescue false); expected_result } rescue !expected_result
58
+ end
59
+
60
+ def be_prefix
61
+ @predicate.to_s[0..-2] == "exist" ? "" : "be "
62
+ end
63
+
64
+ def timeout_to_s
65
+ if @within_seconds
66
+ " within #{@within_seconds} second(s) "
67
+ elsif @during_seconds
68
+ " during #{@during_seconds} second(s) "
69
+ else
70
+ " "
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -1,5 +1,5 @@
1
1
  module Watir
2
2
  class RSpec
3
- VERSION = "0.0.3"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -0,0 +1,18 @@
1
+ require "simplecov"
2
+ require 'coveralls'
3
+
4
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
5
+ SimpleCov.start
6
+
7
+ RSpec.configure do |c|
8
+ c.color = true
9
+ c.order = :random
10
+ end
11
+
12
+ # Make sure constants are defined
13
+ module ::ActiveRecord
14
+ class Base
15
+ end
16
+ end
17
+
18
+ require "watir/rspec"
@@ -0,0 +1,24 @@
1
+ require "spec_helper"
2
+
3
+ describe ::ActiveRecord::Base do
4
+ before { described_class.instance_variable_set :@shared_connection, nil }
5
+
6
+ context ".connection" do
7
+ it "reuses the connection" do
8
+ described_class.should_receive(:retrieve_connection).once.and_return(:established_connection)
9
+
10
+ 2.times { described_class.connection.should == :established_connection }
11
+ end
12
+
13
+ it "uses mutex" do
14
+ described_class.should_receive(:retrieve_connection).once { sleep 0.1; :established_connection }
15
+
16
+ thr = Thread.new { described_class.connection }
17
+
18
+ t = Time.now
19
+ described_class.connection
20
+ (Time.now - t).should be >= 0.1
21
+ thr.join
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,56 @@
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
+ browser.should == @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
+ browser.should == @browser
17
+ end
18
+
19
+ it "delegates to $browser if @browser does not exist" do
20
+ $browser = :global_browser
21
+ browser.should == $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
+ coolness_factor.should == :very
29
+ end
30
+
31
+ it "raises error when browser does not have method" do
32
+ @browser = double("browser")
33
+ described_class.should_not be_method_defined :not_existing_method
34
+
35
+ expect do
36
+ self.not_existing_method
37
+ end.to raise_error(NoMethodError)
38
+
39
+ described_class.should_not be_method_defined :not_existing_method
40
+ end
41
+
42
+ it "adds browser methods to the helper" do
43
+ @browser = double("browser", method_to_be_defined: :done)
44
+ described_class.should_not be_method_defined :method_to_be_defined
45
+ method_to_be_defined.should == :done
46
+ described_class.should 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
+ described_class.should_not_receive(:method_missing)
53
+
54
+ p.should == "#p"
55
+ end
56
+ end
@@ -0,0 +1,177 @@
1
+ require "spec_helper"
2
+
3
+ describe Watir::RSpec::Matchers::BaseMatcher do
4
+ before { self.class.send(:define_method, :be_foo) { described_class.new :foo? } }
5
+
6
+ it "#matches?" do
7
+ object = double("element", foo?: true)
8
+ object.should be_foo
9
+ end
10
+
11
+ it "#matches? with error" do
12
+ object = double("element", foo?: false)
13
+ expect {
14
+ object.should be_foo
15
+ }.to raise_error(RSpec::Expectations::ExpectationNotMetError)
16
+ end
17
+
18
+ it "#does_not_match?" do
19
+ object = double("element", foo?: false)
20
+ object.should_not be_foo
21
+ end
22
+
23
+ it "#does_not_match? with error" do
24
+ object = double("element", foo?: true)
25
+ expect {
26
+ object.should_not be_foo
27
+ }.to raise_error(RSpec::Expectations::ExpectationNotMetError)
28
+ end
29
+
30
+ context "#within" do
31
+ around { |example| should_take_at_least(0.1) { example.run }}
32
+
33
+ it "#matches?" do
34
+ object = double("element")
35
+ @result = false
36
+ object.stub(:foo?) { @result }
37
+ thr = Thread.new { sleep 0.1; @result = true }
38
+
39
+ object.should be_foo.within(1)
40
+ thr.join
41
+ end
42
+
43
+ it "#matches? with timeout error" do
44
+ object = double("element", foo?: false)
45
+
46
+ expect {
47
+ object.should be_foo.within(0.1)
48
+ }.to raise_error(RSpec::Expectations::ExpectationNotMetError)
49
+ end
50
+
51
+ it "#matches? with some other error" do
52
+ object = double("element")
53
+ raised = false
54
+ object.stub(:foo?) do
55
+ unless raised
56
+ raised = true
57
+ raise "Some unexpected exception"
58
+ else
59
+ sleep 0.1
60
+ true
61
+ end
62
+ end
63
+
64
+ object.should be_foo.within(1)
65
+ end
66
+
67
+ it "#does_not_match?" do
68
+ object = double("element")
69
+ @result = true
70
+ object.stub(:foo?) { @result }
71
+ thr = Thread.new { sleep 0.1; @result = false }
72
+
73
+ object.should_not be_foo.within(1)
74
+ thr.join
75
+ end
76
+
77
+ it "#does_not_match? with timeout error" do
78
+ object = double("element", foo?: true)
79
+
80
+ expect {
81
+ object.should_not be_foo.within(0.1)
82
+ }.to raise_error(RSpec::Expectations::ExpectationNotMetError)
83
+ end
84
+
85
+ it "#does_not_match? with some other error" do
86
+ object = double("element")
87
+ raised = false
88
+ object.stub(:foo?) do
89
+ unless raised
90
+ raised = true
91
+ raise "Some unexpected exception"
92
+ else
93
+ sleep 0.1
94
+ false
95
+ end
96
+ end
97
+
98
+ object.should_not be_foo.within(1)
99
+ end
100
+ end
101
+
102
+ context "#during" do
103
+ around { |example| should_take_at_least(0.1) { example.run }}
104
+
105
+ it "#matches?" do
106
+ object = double("element", foo?: true)
107
+
108
+ object.should be_foo.during(0.1)
109
+ end
110
+
111
+ it "#matches? with timeout error" do
112
+ object = double("element")
113
+ @result = true
114
+ object.stub(:foo?) { @result }
115
+ thr = Thread.new { sleep 0.1; @result = false }
116
+
117
+ expect {
118
+ object.should be_foo.during(1)
119
+ }.to raise_error(RSpec::Expectations::ExpectationNotMetError)
120
+ thr.join
121
+ end
122
+
123
+ it "#matches? with some other error" do
124
+ object = double("element")
125
+ raised = false
126
+ object.stub(:foo?) do
127
+ unless raised
128
+ raised = true
129
+ raise "Some unexpected exception"
130
+ else
131
+ true
132
+ end
133
+ end
134
+
135
+ object.should be_foo.during(0.1)
136
+ end
137
+
138
+ it "#does_not_match?" do
139
+ object = double("element", foo?: false)
140
+
141
+ object.should_not be_foo.during(0.1)
142
+ end
143
+
144
+ it "#does_not_match? with timeout error" do
145
+ object = double("element")
146
+ @result = false
147
+ object.stub(:foo?) { @result }
148
+ thr = Thread.new { sleep 0.1; @result = true }
149
+
150
+ expect {
151
+ object.should_not be_foo.during(1)
152
+ }.to raise_error(RSpec::Expectations::ExpectationNotMetError)
153
+ thr.join
154
+ end
155
+
156
+ it "#does_not_match? with some other error" do
157
+ object = double("element")
158
+ raised = false
159
+ object.stub(:foo?) do
160
+ unless raised
161
+ raised = true
162
+ raise "Some unexpected exception"
163
+ else
164
+ false
165
+ end
166
+ end
167
+
168
+ object.should_not be_foo.during(0.1)
169
+ end
170
+ end
171
+
172
+ def should_take_at_least(seconds)
173
+ t = Time.now
174
+ yield
175
+ (Time.now - t).should be >= seconds
176
+ end
177
+ end
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ describe Watir::RSpec::Matchers do
4
+ before { self.send :extend, described_class }
5
+
6
+ it "#be_present" do
7
+ matcher = be_present
8
+ matcher.should == Watir::RSpec::Matchers::BaseMatcher
9
+ matcher.instance_variable_get(:@predicate).should == :present?
10
+ end
11
+
12
+ it "#be_visible" do
13
+ matcher = be_visible
14
+ matcher.should == Watir::RSpec::Matchers::BaseMatcher
15
+ matcher.instance_variable_get(:@predicate).should == :visible?
16
+ end
17
+
18
+ it "#exist" do
19
+ matcher = exist
20
+ matcher.should == Watir::RSpec::Matchers::BaseMatcher
21
+ matcher.instance_variable_get(:@predicate).should == :exist?
22
+ end
23
+ end
@@ -1,23 +1,23 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/watir/rspec/version', __FILE__)
3
-
4
- Gem::Specification.new do |gem|
5
- gem.authors = ["Jarmo Pertman"]
6
- gem.email = ["jarmo.p@gmail.com"]
7
- gem.description = %q{Use Watir with RSpec with ease.}
8
- gem.summary = %q{Use Watir with RSpec with ease.}
9
- gem.homepage = "http://github.com/watir/watir-rspec"
10
-
11
- gem.files = `git ls-files`.split($\)
12
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
- gem.name = "watir-rspec"
15
- gem.require_paths = ["lib"]
16
- gem.version = Watir::RSpec::VERSION
17
-
18
- gem.add_dependency "rspec", "~>2.0"
19
-
20
- gem.add_development_dependency "yard"
21
- gem.add_development_dependency "rake"
22
- gem.add_development_dependency "redcarpet"
23
- end
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/watir/rspec/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Jarmo Pertman"]
6
+ gem.email = ["jarmo.p@gmail.com"]
7
+ gem.description = %q{Use Watir with RSpec with ease.}
8
+ gem.summary = %q{Use Watir with RSpec with ease.}
9
+ gem.homepage = "http://github.com/watir/watir-rspec"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "watir-rspec"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Watir::RSpec::VERSION
17
+
18
+ gem.add_dependency "rspec", "~>2.0"
19
+
20
+ gem.add_development_dependency "yard"
21
+ gem.add_development_dependency "rake"
22
+ gem.add_development_dependency "redcarpet"
23
+ end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watir-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jarmo Pertman
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-03 00:00:00.000000000 Z
11
+ date: 2013-09-21 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,93 +27,103 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: yard
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: redcarpet
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  description: Use Watir with RSpec with ease.
79
70
  email:
80
71
  - jarmo.p@gmail.com
81
- executables: []
72
+ executables:
73
+ - watir-rspec
82
74
  extensions: []
83
75
  extra_rdoc_files: []
84
76
  files:
85
77
  - .gitignore
78
+ - .travis.yml
86
79
  - .yardopts
80
+ - CHANGES
87
81
  - Gemfile
88
82
  - LICENSE
89
83
  - README.md
90
84
  - Rakefile
85
+ - bin/watir-rspec
91
86
  - lib/watir/rspec.rb
92
87
  - lib/watir/rspec/active_record_shared_connection.rb
88
+ - lib/watir/rspec/cli.rb
93
89
  - lib/watir/rspec/helper.rb
94
90
  - lib/watir/rspec/html_formatter.rb
91
+ - lib/watir/rspec/matchers.rb
92
+ - lib/watir/rspec/matchers/base_matcher.rb
95
93
  - lib/watir/rspec/version.rb
94
+ - spec/spec_helper.rb
95
+ - spec/watir/rspec/active_record_shared_connection_spec.rb
96
+ - spec/watir/rspec/helper_spec.rb
97
+ - spec/watir/rspec/matchers/base_matcher_spec.rb
98
+ - spec/watir/rspec/matchers_spec.rb
96
99
  - watir-rspec.gemspec
97
100
  homepage: http://github.com/watir/watir-rspec
98
101
  licenses: []
102
+ metadata: {}
99
103
  post_install_message:
100
104
  rdoc_options: []
101
105
  require_paths:
102
106
  - lib
103
107
  required_ruby_version: !ruby/object:Gem::Requirement
104
- none: false
105
108
  requirements:
106
- - - ! '>='
109
+ - - '>='
107
110
  - !ruby/object:Gem::Version
108
111
  version: '0'
109
112
  required_rubygems_version: !ruby/object:Gem::Requirement
110
- none: false
111
113
  requirements:
112
- - - ! '>='
114
+ - - '>='
113
115
  - !ruby/object:Gem::Version
114
116
  version: '0'
115
117
  requirements: []
116
118
  rubyforge_project:
117
- rubygems_version: 1.8.24
119
+ rubygems_version: 2.0.7
118
120
  signing_key:
119
- specification_version: 3
121
+ specification_version: 4
120
122
  summary: Use Watir with RSpec with ease.
121
- test_files: []
123
+ test_files:
124
+ - spec/spec_helper.rb
125
+ - spec/watir/rspec/active_record_shared_connection_spec.rb
126
+ - spec/watir/rspec/helper_spec.rb
127
+ - spec/watir/rspec/matchers/base_matcher_spec.rb
128
+ - spec/watir/rspec/matchers_spec.rb
122
129
  has_rdoc: