rspec-wait 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8de02581ff92b52a5e1bb18a295912344b2fc87c
4
+ data.tar.gz: ce87d11fd20e6b19ecd4f5792a2836c0f0e55967
5
+ SHA512:
6
+ metadata.gz: 172c31ce4a7d6eb87832d2a55f4642e029ff9ab90457163a42ceef008d0080b1a8d50271df0ae1f0b826da864c50b04f45bc9c424058f12889e064ae0fbda8d2
7
+ data.tar.gz: bc4abe75a8f37f274e92ba924e82b85afc9bd145f92d102891cbc4a54783d64f9f09985c5b0403801d7d54254479a80698b7ce7a1b60d90737c01a8cc099ffea
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ gemfiles/*.lock
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,29 @@
1
+ before_install:
2
+ - gem update bundler
3
+ branches:
4
+ only:
5
+ - master
6
+ gemfile:
7
+ - gemfiles/rspec_2_11.gemfile
8
+ - gemfiles/rspec_2_12.gemfile
9
+ - gemfiles/rspec_2_13.gemfile
10
+ - gemfiles/rspec_2_14.gemfile
11
+ - gemfiles/rspec_3_0.gemfile
12
+ language: ruby
13
+ matrix:
14
+ allow_failures:
15
+ - rvm: ruby-head
16
+ include:
17
+ - env:
18
+ secure: | # CODECLIMATE_REPO_TOKEN
19
+ lK3tYDk/63jRamEfGKbC27mPAoV7XsebCurx6doeisv1r4926lyPY4B9ZoSu
20
+ OeVmjXQWHX9U7IgPH1C+zoIh1wVHVA8h5FVuqlGUMlA6IJi2xaI+ChEo3WeD
21
+ FRlk1Q5fGhgp1mt59sMn3GZZ/mv31v+sd9iYC3AVIM0KrlMGGZQ=
22
+ gemfile: Gemfile
23
+ rvm: "2.1"
24
+ rvm:
25
+ - 1.9.3
26
+ - 2.0.0
27
+ - "2.1"
28
+ - ruby-head
29
+ script: bundle exec rspec
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 0.0.1 / 2014-04-18
2
+
3
+ * Initial release!
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,48 @@
1
+ # Contributing to RSpec::Wait
2
+
3
+ RSpec::Wait is open source and contributions from the community are encouraged!
4
+ No contribution is too small.
5
+
6
+ Please consider:
7
+
8
+ * Adding a feature
9
+ * Squashing a bug
10
+ * Writing documentation
11
+ * Fixing a typo
12
+ * Correcting [style](https://github.com/styleguide/ruby)
13
+
14
+ ## How do I contribute?
15
+
16
+ For the best chance of having your changes merged, please:
17
+
18
+ 1. [Fork](https://github.com/laserlemon/rspec-wait/fork) the project.
19
+ 2. [Write](http://en.wikipedia.org/wiki/Test-driven_development) a failing test.
20
+ 3. [Commit](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) changes that fix the tests.
21
+ 4. [Submit](https://github.com/laserlemon/rspec-wait/pulls) a pull request with *at least* one animated GIF.
22
+ 5. Be patient.
23
+
24
+ If your proposed changes only affect documentation, include the following on a
25
+ new line in each of your commit messages:
26
+
27
+ ```
28
+ [ci skip]
29
+ ```
30
+
31
+ This will signal [Travis](https://travis-ci.org) that running the test suite is
32
+ not necessary for these changes.
33
+
34
+ ## Bug Reports
35
+
36
+ If you are experiencing unexpected behavior and, after having read RSpec::Wait's
37
+ documentation, are convinced this behavior is a bug, please:
38
+
39
+ 1. [Search](https://github.com/laserlemon/rspec-wait/issues) existing issues.
40
+ 2. Collect enough information to reproduce the issue:
41
+ * RSpec::Wait version
42
+ * Ruby version
43
+ * RSpec version
44
+ * Specific setup conditions
45
+ * Description of expected behavior
46
+ * Description of actual behavior
47
+ 3. [Submit](https://github.com/laserlemon/rspec-wait/issues/new) an issue.
48
+ 4. Be patient.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "codeclimate-test-reporter", require: false
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Steve Richert
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # RSpec::Wait
2
+
3
+ Wait for conditions in RSpec
4
+
5
+ [![Gem Version](https://img.shields.io/gem/v/rspec-wait.svg)](http://badge.fury.io/rb/rspec-wait)
6
+ [![Build Status](https://img.shields.io/travis/laserlemon/rspec-wait/master.svg)](https://travis-ci.org/laserlemon/rspec-wait)
7
+ [![Code Climate](https://img.shields.io/codeclimate/github/laserlemon/rspec-wait.svg)](https://codeclimate.com/github/laserlemon/rspec-wait)
8
+ [![Coverage Status](https://img.shields.io/codeclimate/coverage/github/laserlemon/rspec-wait.svg)](https://codeclimate.com/github/laserlemon/rspec-wait)
9
+ [![Dependency Status](https://img.shields.io/gemnasium/laserlemon/rspec-wait.svg)](https://gemnasium.com/laserlemon/rspec-wait)
10
+
11
+ ## Why does RSpec::Wait exist?
12
+
13
+ Timing is hard.
14
+
15
+ Timing problems and race conditions can plague your test suite. As your test
16
+ suite slowly becomes less reliable, development speed and quality suffer.
17
+
18
+ RSpec::Wait strives to make it easier to test asynchronous or slow interactions.
19
+
20
+ ## How does RSpec::Wait work?
21
+
22
+ RSpec::Wait allows you to wait for an assertion to pass, using the RSpec
23
+ syntactic sugar that you already know and love.
24
+
25
+ RSpec::Wait will keep trying until your assertion passes or times out.
26
+
27
+ ### Example
28
+
29
+ RSpec::Wait's `wait_for` assertions are drop-in replacements for RSpec's
30
+ `expect` assertions.
31
+
32
+ ```ruby
33
+ describe Ticker do
34
+ subject(:ticker) { Ticker.new("foo") }
35
+
36
+ describe "#start" do
37
+ before do
38
+ ticker.start
39
+ end
40
+
41
+ it "starts a blank tape" do
42
+ expect(ticker.tape).to eq("")
43
+ end
44
+
45
+ it "writes the message one letter at a time" do
46
+ wait_for(ticker.tape).to eq("··-·")
47
+ wait_for(ticker.tape).to eq("··-· ---")
48
+ wait_for(ticker.tape).to eq("··-· --- ---")
49
+ end
50
+ end
51
+ end
52
+ ```
53
+
54
+ This can be especially useful for testing user interfaces with tricky timing
55
+ elements like JavaScript interactions or remote requests.
56
+
57
+ ```ruby
58
+ feature "User Login" do
59
+ let!(:user) { create(:user, name: "John Doe", email: "john@example.com", password: "secret") }
60
+
61
+ scenario "A user can log in successfully" do
62
+ visit new_session_path
63
+
64
+ fill_in "Email", with: "john@example.com"
65
+ fill_in "Password", with: "secret"
66
+ click_button "Log In"
67
+
68
+ wait_for { current_path }.to eq(account_path)
69
+ expect(page).to have_content("John Doe")
70
+ end
71
+ end
72
+ ```
73
+
74
+ ### Matchers
75
+
76
+ RSpec::Wait ties into RSpec's internals so it can take full advantage of any
77
+ matcher that you would use with RSpec's own `expect` method.
78
+
79
+ ## Who wrote RSpec::Wait?
80
+
81
+ My name is Steve Richert and I wrote RSpec::Wait in April, 2014 with the support
82
+ of my employer, [Collective Idea](http://www.collectiveidea.com). RSpec::Wait
83
+ owes its current and future success entirely to [inspiration](https://github.com/laserlemon/rspec-wait/issues)
84
+ and [contribution](https://github.com/laserlemon/rspec-wait/graphs/contributors)
85
+ from the Ruby community, especially the [authors and maintainers](https://github.com/rspec/rspec-core/graphs/contributors)
86
+ of RSpec.
87
+
88
+ **Thank you!**
89
+
90
+ ## How can I help?
91
+
92
+ RSpec::Wait is open source and contributions from the community are encouraged!
93
+ No contribution is too small.
94
+
95
+ See RSpec::Wait's [contribution guidelines](CONTRIBUTING.md) for more
96
+ information.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec path: ".."
4
+
5
+ gem "rspec", "~> 2.11.0"
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec path: ".."
4
+
5
+ gem "rspec", "~> 2.12.0"
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec path: ".."
4
+
5
+ gem "rspec", "~> 2.13.0"
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec path: ".."
4
+
5
+ gem "rspec", "~> 2.14.0"
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec path: ".."
4
+
5
+ gem "rspec", "~> 3.0.0.beta"
data/lib/rspec/wait.rb ADDED
@@ -0,0 +1,20 @@
1
+ require "rspec"
2
+
3
+ require "rspec/wait/error"
4
+ require "rspec/wait/handler"
5
+ require "rspec/wait/target"
6
+
7
+ module RSpec
8
+ module Wait
9
+ # From: https://github.com/rspec/rspec-expectations/blob/v2.14.5/lib/rspec/expectations/syntax.rb#L83-L87
10
+ def wait_for(*target, &target_block)
11
+ target << target_block if block_given?
12
+ raise ArgumentError.new("You must pass an argument or a block to #wait_for but not both.") unless target.size == 1
13
+ Target.new(target.first)
14
+ end
15
+ end
16
+ end
17
+
18
+ RSpec.configure do |config|
19
+ config.include(RSpec::Wait)
20
+ end
@@ -0,0 +1,7 @@
1
+ module RSpec
2
+ module Wait
3
+ class Error < StandardError; end
4
+
5
+ class TimeoutError < Error; end
6
+ end
7
+ end
@@ -0,0 +1,42 @@
1
+ require "rspec"
2
+ require "timeout"
3
+
4
+ require "rspec/wait/error"
5
+
6
+ module RSpec
7
+ module Wait
8
+ module Handler
9
+ TIMEOUT = 10
10
+ DELAY = 0.1
11
+
12
+ # From: https://github.com/rspec/rspec-expectations/blob/v2.14.5/lib/rspec/expectations/handler.rb#L16-L64
13
+ def handle_matcher(actual, *)
14
+ failure = nil
15
+
16
+ Timeout.timeout(TIMEOUT) do
17
+ loop do
18
+ actual = actual.call if actual.respond_to?(:call)
19
+
20
+ begin
21
+ super
22
+ break
23
+ rescue RSpec::Expectations::ExpectationNotMetError => failure
24
+ sleep DELAY
25
+ retry
26
+ end
27
+ end
28
+ end
29
+ rescue Timeout::Error
30
+ raise failure || TimeoutError
31
+ end
32
+ end
33
+
34
+ class PositiveHandler < RSpec::Expectations::PositiveExpectationHandler
35
+ extend Handler
36
+ end
37
+
38
+ class NegativeHandler < RSpec::Expectations::NegativeExpectationHandler
39
+ extend Handler
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,21 @@
1
+ require "rspec"
2
+
3
+ require "rspec/wait/handler"
4
+
5
+ module RSpec
6
+ module Wait
7
+ class Target < RSpec::Expectations::ExpectationTarget
8
+ # From: https://github.com/rspec/rspec-expectations/blob/v2.14.5/lib/rspec/expectations/expectation_target.rb#L32-L35
9
+ def to(matcher = nil, message = nil, &block)
10
+ prevent_operator_matchers(:to, matcher)
11
+ PositiveHandler.handle_matcher(@target, matcher, message, &block)
12
+ end
13
+
14
+ # From: https://github.com/rspec/rspec-expectations/blob/v2.14.5/lib/rspec/expectations/expectation_target.rb#L45-L48
15
+ def not_to(matcher = nil, message = nil, &block)
16
+ prevent_operator_matchers(:not_to, matcher)
17
+ NegativeHandler.handle_matcher(@target, matcher, message, &block)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "rspec-wait"
5
+ spec.version = "0.0.1"
6
+
7
+ spec.author = "Steve Richert"
8
+ spec.email = "steve.richert@gmail.com"
9
+ spec.summary = "Wait for conditions in RSpec"
10
+ spec.description = spec.summary
11
+ spec.homepage = "https://github.com/laserlemon/rspec-wait"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.test_files = spec.files.grep(/^spec/)
16
+
17
+ spec.add_dependency "rspec", ">= 2.11", "< 3.1"
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.6"
20
+ spec.add_development_dependency "rake", "~> 10.3"
21
+ end
@@ -0,0 +1,8 @@
1
+ if ENV["CODECLIMATE_REPO_TOKEN"]
2
+ require "codeclimate-test-reporter"
3
+ CodeClimate::TestReporter.start
4
+ end
5
+
6
+ require "rspec/wait"
7
+
8
+ Dir[File.expand_path("../support/*.rb", __FILE__)].each { |f| require f }
@@ -0,0 +1,3 @@
1
+ RSpec.configure do |config|
2
+ config.order = "random"
3
+ end
@@ -0,0 +1,96 @@
1
+ require "spec_helper"
2
+
3
+ describe "wait_for" do
4
+ let!(:progress) { "" }
5
+
6
+ before do
7
+ Thread.new do
8
+ 2.times do
9
+ sleep 1
10
+ progress << "."
11
+ end
12
+ end
13
+ end
14
+
15
+ context "to" do
16
+ it "passes immediately" do
17
+ expect {
18
+ wait_for(progress).to eq("")
19
+ }.not_to raise_error
20
+ end
21
+
22
+ it "waits for the matcher to pass" do
23
+ expect {
24
+ wait_for(progress).to eq(".")
25
+ }.not_to raise_error
26
+ end
27
+
28
+ it "accepts a block" do
29
+ expect {
30
+ wait_for { progress }.to eq(".")
31
+ }.not_to raise_error
32
+ end
33
+
34
+ it "fails if the matcher never passes" do
35
+ expect {
36
+ wait_for(progress).to eq("...")
37
+ }.to raise_error(RSpec::Expectations::ExpectationNotMetError)
38
+ end
39
+
40
+ it "times out if the block never finishes" do
41
+ expect {
42
+ wait_for { sleep 11; progress }.to eq("..")
43
+ }.to raise_error(RSpec::Wait::TimeoutError)
44
+ end
45
+
46
+ it "raises an error occuring in the block" do
47
+ expect {
48
+ wait_for { raise RuntimeError }.to eq("..")
49
+ }.to raise_error(RuntimeError)
50
+ end
51
+ end
52
+
53
+ context "not_to" do
54
+ it "passes immediately" do
55
+ expect {
56
+ wait_for(progress).not_to eq("..")
57
+ }.not_to raise_error
58
+ end
59
+
60
+ it "waits for the matcher not to pass" do
61
+ expect {
62
+ wait_for(progress).not_to eq("")
63
+ }.not_to raise_error
64
+ end
65
+
66
+ it "accepts a block" do
67
+ expect {
68
+ wait_for { progress }.not_to eq("")
69
+ }.not_to raise_error
70
+ end
71
+
72
+ it "fails if the matcher always passes" do
73
+ expect {
74
+ wait_for(progress).not_to be_a(String)
75
+ }.to raise_error(RSpec::Expectations::ExpectationNotMetError)
76
+ end
77
+
78
+ it "times out if the block never finishes" do
79
+ expect {
80
+ wait_for { sleep 11; progress }.not_to eq("..")
81
+ }.to raise_error(RSpec::Wait::TimeoutError)
82
+ end
83
+
84
+ it "raises an error occuring in the block" do
85
+ expect {
86
+ wait_for { raise RuntimeError }.not_to eq("")
87
+ }.to raise_error(RuntimeError)
88
+ end
89
+
90
+ it "respects the to_not alias" do
91
+ expect {
92
+ wait_for(progress).to_not eq("..")
93
+ }.not_to raise_error
94
+ end
95
+ end
96
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-wait
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Steve Richert
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '2.11'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3.1'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '2.11'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3.1'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.6'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.6'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.3'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.3'
61
+ description: Wait for conditions in RSpec
62
+ email: steve.richert@gmail.com
63
+ executables: []
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - ".gitignore"
68
+ - ".travis.yml"
69
+ - CHANGELOG.md
70
+ - CONTRIBUTING.md
71
+ - Gemfile
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - gemfiles/rspec_2_11.gemfile
76
+ - gemfiles/rspec_2_12.gemfile
77
+ - gemfiles/rspec_2_13.gemfile
78
+ - gemfiles/rspec_2_14.gemfile
79
+ - gemfiles/rspec_3_0.gemfile
80
+ - lib/rspec/wait.rb
81
+ - lib/rspec/wait/error.rb
82
+ - lib/rspec/wait/handler.rb
83
+ - lib/rspec/wait/target.rb
84
+ - rspec-wait.gemspec
85
+ - spec/spec_helper.rb
86
+ - spec/support/random.rb
87
+ - spec/wait_for_spec.rb
88
+ homepage: https://github.com/laserlemon/rspec-wait
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.2.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Wait for conditions in RSpec
112
+ test_files:
113
+ - spec/spec_helper.rb
114
+ - spec/support/random.rb
115
+ - spec/wait_for_spec.rb