rspec-wait 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8de02581ff92b52a5e1bb18a295912344b2fc87c
4
- data.tar.gz: ce87d11fd20e6b19ecd4f5792a2836c0f0e55967
3
+ metadata.gz: fa62ab1f0470b41980bbda0f946388a78f785fd5
4
+ data.tar.gz: ee13ca8d70502950209cea78026b457f946671ca
5
5
  SHA512:
6
- metadata.gz: 172c31ce4a7d6eb87832d2a55f4642e029ff9ab90457163a42ceef008d0080b1a8d50271df0ae1f0b826da864c50b04f45bc9c424058f12889e064ae0fbda8d2
7
- data.tar.gz: bc4abe75a8f37f274e92ba924e82b85afc9bd145f92d102891cbc4a54783d64f9f09985c5b0403801d7d54254479a80698b7ce7a1b60d90737c01a8cc099ffea
6
+ metadata.gz: 879ebe4b4dda20745cb76f6d243f29056e21ffbe12e34d6cbe01ff292d7285258034c7df0792ba6e6f9cccd861b45a1d07ab980723c58cbf670192b67002dd34
7
+ data.tar.gz: ca29a21677137114dff82a800942082577c6be3efa2029862917e4d7bc7366431733e6ac8752ba23bcfab069e2b525429d7ca3a77aeba01a28e9420b97a8fd2e
@@ -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.0
24
+ - "2.0"
27
25
  - "2.1"
28
26
  - ruby-head
29
- script: bundle exec rspec
@@ -1,3 +1,8 @@
1
- ## 0.0.1 / 2014-04-18
1
+ ## 0.0.2 / 2014-06-11
2
+
3
+ * [ENHANCEMENT] Allow `wait_for` to accept either a value or block target
4
+ * [BUGFIX] Ensure blocks are re-evaluated with each iteration
5
+
6
+ ## 0.0.1 / 2014-04-19
2
7
 
3
8
  * Initial release!
data/Gemfile CHANGED
@@ -1,5 +1,3 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
-
5
- gem "codeclimate-test-reporter", require: false
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)](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)
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(ticker.tape).to eq("")
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(ticker.tape).to eq("··-·")
47
- wait_for(ticker.tape).to eq("··-· ---")
48
- wait_for(ticker.tape).to eq("··-· --- ---")
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, name: "John Doe", email: "john@example.com", password: "secret") }
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("John Doe")
71
+ expect(page).to have_content("Welcome back!")
70
72
  end
71
73
  end
72
74
  ```
@@ -3,3 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec path: ".."
4
4
 
5
5
  gem "rspec", "~> 2.11.0"
6
+
7
+ group :test do
8
+ gem "codeclimate-test-reporter", require: false
9
+ end
@@ -3,3 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec path: ".."
4
4
 
5
5
  gem "rspec", "~> 2.12.0"
6
+
7
+ group :test do
8
+ gem "codeclimate-test-reporter", require: false
9
+ end
@@ -3,3 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec path: ".."
4
4
 
5
5
  gem "rspec", "~> 2.13.0"
6
+
7
+ group :test do
8
+ gem "codeclimate-test-reporter", require: false
9
+ end
@@ -3,3 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec path: ".."
4
4
 
5
5
  gem "rspec", "~> 2.14.0"
6
+
7
+ group :test do
8
+ gem "codeclimate-test-reporter", require: false
9
+ end
@@ -2,4 +2,8 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec path: ".."
4
4
 
5
- gem "rspec", "~> 3.0.0.beta"
5
+ gem "rspec", "~> 3.0.0"
6
+
7
+ group :test do
8
+ gem "codeclimate-test-reporter", require: false
9
+ end
@@ -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/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)
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
@@ -9,16 +9,14 @@ module RSpec
9
9
  TIMEOUT = 10
10
10
  DELAY = 0.1
11
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, *)
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
- super
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
@@ -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/v2.14.5/lib/rspec/expectations/expectation_target.rb#L32-L35
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/v2.14.5/lib/rspec/expectations/expectation_target.rb#L45-L48
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "rspec-wait"
5
- spec.version = "0.0.1"
5
+ spec.version = "0.0.2"
6
6
 
7
7
  spec.author = "Steve Richert"
8
8
  spec.email = "steve.richert@gmail.com"
@@ -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(progress).to eq("")
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(progress).to eq(".")
24
+ wait_for { progress }.to eq(".")
25
25
  }.not_to raise_error
26
26
  end
27
27
 
28
- it "accepts a block" do
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(progress).to eq("...")
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(progress).not_to eq("..")
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(progress).not_to eq("")
74
+ wait_for { progress }.not_to eq("")
63
75
  }.not_to raise_error
64
76
  end
65
77
 
66
- it "accepts a block" do
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(progress).not_to be_a(String)
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(progress).to_not eq("..")
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.1
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-04-19 00:00:00.000000000 Z
11
+ date: 2014-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec