rspec-wait 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 +4 -4
- data/.travis.yml +7 -10
- data/CHANGELOG.md +6 -1
- data/Gemfile +0 -2
- data/README.md +15 -13
- data/gemfiles/rspec_2_11.gemfile +4 -0
- data/gemfiles/rspec_2_12.gemfile +4 -0
- data/gemfiles/rspec_2_13.gemfile +4 -0
- data/gemfiles/rspec_2_14.gemfile +4 -0
- data/gemfiles/rspec_3_0.gemfile +5 -1
- data/lib/rspec/wait.rb +3 -5
- data/lib/rspec/wait/handler.rb +5 -5
- data/lib/rspec/wait/target.rb +22 -4
- data/rspec-wait.gemspec +1 -1
- data/spec/wait_for_spec.rb +35 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa62ab1f0470b41980bbda0f946388a78f785fd5
|
4
|
+
data.tar.gz: ee13ca8d70502950209cea78026b457f946671ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 879ebe4b4dda20745cb76f6d243f29056e21ffbe12e34d6cbe01ff292d7285258034c7df0792ba6e6f9cccd861b45a1d07ab980723c58cbf670192b67002dd34
|
7
|
+
data.tar.gz: ca29a21677137114dff82a800942082577c6be3efa2029862917e4d7bc7366431733e6ac8752ba23bcfab069e2b525429d7ca3a77aeba01a28e9420b97a8fd2e
|
data/.travis.yml
CHANGED
@@ -3,6 +3,12 @@ before_install:
|
|
3
3
|
branches:
|
4
4
|
only:
|
5
5
|
- master
|
6
|
+
env:
|
7
|
+
global:
|
8
|
+
- secure: | # CODECLIMATE_REPO_TOKEN
|
9
|
+
lK3tYDk/63jRamEfGKbC27mPAoV7XsebCurx6doeisv1r4926lyPY4B9ZoSu
|
10
|
+
OeVmjXQWHX9U7IgPH1C+zoIh1wVHVA8h5FVuqlGUMlA6IJi2xaI+ChEo3WeD
|
11
|
+
FRlk1Q5fGhgp1mt59sMn3GZZ/mv31v+sd9iYC3AVIM0KrlMGGZQ=
|
6
12
|
gemfile:
|
7
13
|
- gemfiles/rspec_2_11.gemfile
|
8
14
|
- gemfiles/rspec_2_12.gemfile
|
@@ -13,17 +19,8 @@ language: ruby
|
|
13
19
|
matrix:
|
14
20
|
allow_failures:
|
15
21
|
- 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
22
|
rvm:
|
25
23
|
- 1.9.3
|
26
|
-
- 2.0
|
24
|
+
- "2.0"
|
27
25
|
- "2.1"
|
28
26
|
- ruby-head
|
29
|
-
script: bundle exec rspec
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Wait for conditions in RSpec
|
4
4
|
|
5
|
-
[![Gem Version](https://img.shields.io/gem/v/rspec-wait.svg)](
|
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)
|
5
|
+
[![Gem Version](https://img.shields.io/gem/v/rspec-wait.svg?style=flat)](https://rubygems.org/gems/rspec-wait)
|
6
|
+
[![Build Status](https://img.shields.io/travis/laserlemon/rspec-wait/master.svg?style=flat)](https://travis-ci.org/laserlemon/rspec-wait)
|
7
|
+
[![Code Climate](https://img.shields.io/codeclimate/github/laserlemon/rspec-wait.svg?style=flat)](https://codeclimate.com/github/laserlemon/rspec-wait)
|
8
|
+
[![Coverage Status](https://img.shields.io/codeclimate/coverage/github/laserlemon/rspec-wait.svg?style=flat)](https://codeclimate.com/github/laserlemon/rspec-wait)
|
9
|
+
[![Dependency Status](https://img.shields.io/gemnasium/laserlemon/rspec-wait.svg?style=flat)](https://gemnasium.com/laserlemon/rspec-wait)
|
10
10
|
|
11
11
|
## Why does RSpec::Wait exist?
|
12
12
|
|
@@ -26,8 +26,10 @@ RSpec::Wait will keep trying until your assertion passes or times out.
|
|
26
26
|
|
27
27
|
### Example
|
28
28
|
|
29
|
-
RSpec::Wait's `wait_for` assertions are drop-in replacements for RSpec's
|
30
|
-
`expect` assertions.
|
29
|
+
RSpec::Wait's `wait_for` assertions are nearly drop-in replacements for RSpec's
|
30
|
+
`expect` assertions. The major difference is that the `wait_for` method always
|
31
|
+
accepts a block because it may evaluate the content of that block multiple times
|
32
|
+
while waiting.
|
31
33
|
|
32
34
|
```ruby
|
33
35
|
describe Ticker do
|
@@ -39,13 +41,13 @@ describe Ticker do
|
|
39
41
|
end
|
40
42
|
|
41
43
|
it "starts a blank tape" do
|
42
|
-
expect
|
44
|
+
expect { ticker.tape }.to eq("")
|
43
45
|
end
|
44
46
|
|
45
47
|
it "writes the message one letter at a time" do
|
46
|
-
wait_for
|
47
|
-
wait_for
|
48
|
-
wait_for
|
48
|
+
wait_for { ticker.tape }.to eq("··-·")
|
49
|
+
wait_for { ticker.tape }.to eq("··-· ---")
|
50
|
+
wait_for { ticker.tape }.to eq("··-· --- ---")
|
49
51
|
end
|
50
52
|
end
|
51
53
|
end
|
@@ -56,7 +58,7 @@ elements like JavaScript interactions or remote requests.
|
|
56
58
|
|
57
59
|
```ruby
|
58
60
|
feature "User Login" do
|
59
|
-
let!(:user) { create(:user,
|
61
|
+
let!(:user) { create(:user, email: "john@example.com", password: "secret") }
|
60
62
|
|
61
63
|
scenario "A user can log in successfully" do
|
62
64
|
visit new_session_path
|
@@ -66,7 +68,7 @@ feature "User Login" do
|
|
66
68
|
click_button "Log In"
|
67
69
|
|
68
70
|
wait_for { current_path }.to eq(account_path)
|
69
|
-
expect(page).to have_content("
|
71
|
+
expect(page).to have_content("Welcome back!")
|
70
72
|
end
|
71
73
|
end
|
72
74
|
```
|
data/gemfiles/rspec_2_11.gemfile
CHANGED
data/gemfiles/rspec_2_12.gemfile
CHANGED
data/gemfiles/rspec_2_13.gemfile
CHANGED
data/gemfiles/rspec_2_14.gemfile
CHANGED
data/gemfiles/rspec_3_0.gemfile
CHANGED
data/lib/rspec/wait.rb
CHANGED
@@ -6,11 +6,9 @@ require "rspec/wait/target"
|
|
6
6
|
|
7
7
|
module RSpec
|
8
8
|
module Wait
|
9
|
-
# From: https://github.com/rspec/rspec-expectations/blob/
|
10
|
-
def wait_for(
|
11
|
-
|
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)
|
9
|
+
# From: https://github.com/rspec/rspec-expectations/blob/v3.0.0/lib/rspec/expectations/syntax.rb#L72-L74
|
10
|
+
def wait_for(value = Target::UndefinedValue, &block)
|
11
|
+
Target.for(value, block)
|
14
12
|
end
|
15
13
|
end
|
16
14
|
end
|
data/lib/rspec/wait/handler.rb
CHANGED
@@ -9,16 +9,14 @@ module RSpec
|
|
9
9
|
TIMEOUT = 10
|
10
10
|
DELAY = 0.1
|
11
11
|
|
12
|
-
|
13
|
-
def handle_matcher(actual, *)
|
12
|
+
def handle_matcher(target, *args, &block)
|
14
13
|
failure = nil
|
15
14
|
|
16
15
|
Timeout.timeout(TIMEOUT) do
|
17
16
|
loop do
|
18
|
-
actual = actual.call if actual.respond_to?(:call)
|
19
|
-
|
20
17
|
begin
|
21
|
-
|
18
|
+
actual = target.respond_to?(:call) ? target.call : target
|
19
|
+
super(actual, *args, &block)
|
22
20
|
break
|
23
21
|
rescue RSpec::Expectations::ExpectationNotMetError => failure
|
24
22
|
sleep DELAY
|
@@ -31,10 +29,12 @@ module RSpec
|
|
31
29
|
end
|
32
30
|
end
|
33
31
|
|
32
|
+
# From: https://github.com/rspec/rspec-expectations/blob/v3.0.0/lib/rspec/expectations/handler.rb#L44-L63
|
34
33
|
class PositiveHandler < RSpec::Expectations::PositiveExpectationHandler
|
35
34
|
extend Handler
|
36
35
|
end
|
37
36
|
|
37
|
+
# From: https://github.com/rspec/rspec-expectations/blob/v3.0.0/lib/rspec/expectations/handler.rb#L66-L93
|
38
38
|
class NegativeHandler < RSpec::Expectations::NegativeExpectationHandler
|
39
39
|
extend Handler
|
40
40
|
end
|
data/lib/rspec/wait/target.rb
CHANGED
@@ -5,15 +5,33 @@ require "rspec/wait/handler"
|
|
5
5
|
module RSpec
|
6
6
|
module Wait
|
7
7
|
class Target < RSpec::Expectations::ExpectationTarget
|
8
|
-
# From: https://github.com/rspec/rspec-expectations/blob/
|
8
|
+
# From: https://github.com/rspec/rspec-expectations/blob/v3.0.0/lib/rspec/expectations/expectation_target.rb#L22
|
9
|
+
UndefinedValue = Module.new
|
10
|
+
|
11
|
+
# From: https://github.com/rspec/rspec-expectations/blob/v3.0.0/lib/rspec/expectations/expectation_target.rb#L30-L41
|
12
|
+
def self.for(value, block)
|
13
|
+
if UndefinedValue.equal?(value)
|
14
|
+
unless block
|
15
|
+
raise ArgumentError, "You must pass either an argument or a block to `wait_for`."
|
16
|
+
end
|
17
|
+
new(block)
|
18
|
+
elsif block
|
19
|
+
raise ArgumentError, "You cannot pass both an argument and a block to `wait_for`."
|
20
|
+
else
|
21
|
+
new(value)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
#
|
25
|
+
#
|
26
|
+
# From: https://github.com/rspec/rspec-expectations/blob/v3.0.0/lib/rspec/expectations/expectation_target.rb#L53-L54
|
9
27
|
def to(matcher = nil, message = nil, &block)
|
10
|
-
prevent_operator_matchers(:to, matcher)
|
28
|
+
prevent_operator_matchers(:to, matcher) unless matcher
|
11
29
|
PositiveHandler.handle_matcher(@target, matcher, message, &block)
|
12
30
|
end
|
13
31
|
|
14
|
-
# From: https://github.com/rspec/rspec-expectations/blob/
|
32
|
+
# From: https://github.com/rspec/rspec-expectations/blob/v3.0.0/lib/rspec/expectations/expectation_target.rb#L66-L67
|
15
33
|
def not_to(matcher = nil, message = nil, &block)
|
16
|
-
prevent_operator_matchers(:not_to, matcher)
|
34
|
+
prevent_operator_matchers(:not_to, matcher) unless matcher
|
17
35
|
NegativeHandler.handle_matcher(@target, matcher, message, &block)
|
18
36
|
end
|
19
37
|
end
|
data/rspec-wait.gemspec
CHANGED
data/spec/wait_for_spec.rb
CHANGED
@@ -15,25 +15,25 @@ describe "wait_for" do
|
|
15
15
|
context "to" do
|
16
16
|
it "passes immediately" do
|
17
17
|
expect {
|
18
|
-
wait_for
|
18
|
+
wait_for { progress }.to eq("")
|
19
19
|
}.not_to raise_error
|
20
20
|
end
|
21
21
|
|
22
22
|
it "waits for the matcher to pass" do
|
23
23
|
expect {
|
24
|
-
wait_for
|
24
|
+
wait_for { progress }.to eq(".")
|
25
25
|
}.not_to raise_error
|
26
26
|
end
|
27
27
|
|
28
|
-
it "
|
28
|
+
it "re-evaluates the actual value" do
|
29
29
|
expect {
|
30
|
-
wait_for { progress }.to eq(".")
|
30
|
+
wait_for { progress.dup }.to eq(".")
|
31
31
|
}.not_to raise_error
|
32
32
|
end
|
33
33
|
|
34
34
|
it "fails if the matcher never passes" do
|
35
35
|
expect {
|
36
|
-
wait_for
|
36
|
+
wait_for { progress }.to eq("...")
|
37
37
|
}.to raise_error(RSpec::Expectations::ExpectationNotMetError)
|
38
38
|
end
|
39
39
|
|
@@ -48,30 +48,42 @@ describe "wait_for" do
|
|
48
48
|
wait_for { raise RuntimeError }.to eq("..")
|
49
49
|
}.to raise_error(RuntimeError)
|
50
50
|
end
|
51
|
+
|
52
|
+
it "prevents operator matchers" do
|
53
|
+
expect {
|
54
|
+
wait_for { progress }.to == "."
|
55
|
+
}.to raise_error(ArgumentError)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "accepts a value rather than a block" do
|
59
|
+
expect {
|
60
|
+
wait_for(progress).to eq(".")
|
61
|
+
}.not_to raise_error
|
62
|
+
end
|
51
63
|
end
|
52
64
|
|
53
65
|
context "not_to" do
|
54
66
|
it "passes immediately" do
|
55
67
|
expect {
|
56
|
-
wait_for
|
68
|
+
wait_for { progress }.not_to eq("..")
|
57
69
|
}.not_to raise_error
|
58
70
|
end
|
59
71
|
|
60
72
|
it "waits for the matcher not to pass" do
|
61
73
|
expect {
|
62
|
-
wait_for
|
74
|
+
wait_for { progress }.not_to eq("")
|
63
75
|
}.not_to raise_error
|
64
76
|
end
|
65
77
|
|
66
|
-
it "
|
78
|
+
it "re-evaluates the actual value" do
|
67
79
|
expect {
|
68
|
-
wait_for { progress }.not_to eq("")
|
80
|
+
wait_for { progress.dup }.not_to eq("")
|
69
81
|
}.not_to raise_error
|
70
82
|
end
|
71
83
|
|
72
84
|
it "fails if the matcher always passes" do
|
73
85
|
expect {
|
74
|
-
wait_for
|
86
|
+
wait_for { progress }.not_to be_a(String)
|
75
87
|
}.to raise_error(RSpec::Expectations::ExpectationNotMetError)
|
76
88
|
end
|
77
89
|
|
@@ -89,7 +101,19 @@ describe "wait_for" do
|
|
89
101
|
|
90
102
|
it "respects the to_not alias" do
|
91
103
|
expect {
|
92
|
-
wait_for
|
104
|
+
wait_for { progress }.to_not eq("..")
|
105
|
+
}.not_to raise_error
|
106
|
+
end
|
107
|
+
|
108
|
+
it "prevents operator matchers" do
|
109
|
+
expect {
|
110
|
+
wait_for { progress }.not_to == ".."
|
111
|
+
}.to raise_error(ArgumentError)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "accepts a value rather than a block" do
|
115
|
+
expect {
|
116
|
+
wait_for(progress).not_to eq("..")
|
93
117
|
}.not_to raise_error
|
94
118
|
end
|
95
119
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-wait
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Richert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|