rspec-expect_it 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +103 -0
- data/Rakefile +1 -0
- data/lib/rspec/expect_it/helpers.rb +100 -0
- data/lib/rspec/expect_it/version.rb +5 -0
- data/lib/rspec/expect_it.rb +8 -0
- data/rspec-expect_it.gemspec +26 -0
- data/spec/rspec/expect_it/helpers_spec.rb +127 -0
- data/spec/spec_helper.rb +7 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2ecf0093dc1d268192f7eca5beac2ccce9ea9ebe
|
4
|
+
data.tar.gz: fdcaba0af5f9b4f3d9bf584a97e2df5a6f1d2be7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b6b904136001b584fa0955832372f4a600d3cc18e12248ca1571f03413e58ace5cfc8dab7a89365c293f36397fa6a23400e66b8951bad153fd72d2faff698cb7
|
7
|
+
data.tar.gz: 65b72e0adbc2656eaa1d3cf55b1a7235a0143bd7b883e6b6b6f7fbdac04460f3aea83a552cdc58dd3b90759cc6c8e15e25aec4f838117e39db8cf0b9adecf291
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rspec-expect_it
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0.0-p353
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Thomas Drake-Brockman
|
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,103 @@
|
|
1
|
+
# RSpec::ExpectIt
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/thomasfedb/rspec-expect_it.png?branch=master)](https://travis-ci.org/thomasfedb/rspec-expect_it) [![Gem Version](https://badge.fury.io/rb/rspec-expect_it.png)](http://badge.fury.io/rb/rspec-expect_it)
|
4
|
+
|
5
|
+
Makes writing nice RSpec tests a little easier by providing expect_it helpers.
|
6
|
+
|
7
|
+
Compatible with Ruby 1.9.2 and greater.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem "rspec-expect_it"
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### expect_it
|
22
|
+
The main feature is the `expect_it` helper, which is equivalent to `expect(subject)`.
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
subject { "MyString" }
|
26
|
+
|
27
|
+
specify { expect_it.to eq "MyString" }
|
28
|
+
```
|
29
|
+
|
30
|
+
When you use `expect_it` the `subject` will be evaluated lazily. That is, the matcher
|
31
|
+
will be evaluated before the subject. This can be very helpful, for example:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
let(:posts) { FactoryGirl.create_list :posts, 3 }
|
35
|
+
|
36
|
+
subject { get :index; assigns(:posts) }
|
37
|
+
|
38
|
+
specify { expect_it.to eq posts }
|
39
|
+
```
|
40
|
+
|
41
|
+
If you were using `expect(subject)` you would have to use `let!(:posts)`.
|
42
|
+
|
43
|
+
### expect_it!
|
44
|
+
|
45
|
+
If you want eager evaluation of the subject, use `expect_it!`.
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
subject { @value += 1 }
|
49
|
+
|
50
|
+
specify { expect_it!.to eq(@value) }
|
51
|
+
```
|
52
|
+
|
53
|
+
### expect_it{}
|
54
|
+
|
55
|
+
Calling `expect_it{}` is equivalent to `expect{subject}`.
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
subject { @value += 1 }
|
59
|
+
|
60
|
+
specify { expect_it{}.to change{@value}.by(1) }
|
61
|
+
```
|
62
|
+
|
63
|
+
### expect_it_safe
|
64
|
+
|
65
|
+
The `expect_it_safe` helper is the same as `expect_it`, except that it will
|
66
|
+
swallow any exceptions and return `nil`.
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
subject { raise Exception }
|
70
|
+
|
71
|
+
specify { expect_it_safe.to eq nil }
|
72
|
+
```
|
73
|
+
|
74
|
+
### expect_it_safe!
|
75
|
+
|
76
|
+
The `expect_it_safe!` helper is the same as `expect_it!`, except that it will
|
77
|
+
swallow any exceptions and return `nil`.
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
subject { raise Exception }
|
81
|
+
|
82
|
+
specify { expect_it_safe!.to eq nil }
|
83
|
+
```
|
84
|
+
|
85
|
+
### expect_it_safe{}
|
86
|
+
|
87
|
+
The `expect_it_safe{}` helper is the same as `expect_it{}`, except that it will
|
88
|
+
swallow any exceptions and return `nil`.
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
subject { raise Exception; @value = 12 }
|
92
|
+
|
93
|
+
specify { expect_it_safe{}.to_not change{@value} }
|
94
|
+
```
|
95
|
+
|
96
|
+
## Contributing
|
97
|
+
|
98
|
+
1. Fork it
|
99
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
100
|
+
3. Add your feature and specs.
|
101
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
102
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
103
|
+
6. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module RSpec
|
2
|
+
module ExpectIt
|
3
|
+
module Helpers
|
4
|
+
def expect_it
|
5
|
+
if block_given?
|
6
|
+
ExpectItExpectationTarget.new(self, lambda { self.subject })
|
7
|
+
else
|
8
|
+
ExpectItExpectationTarget.new(self)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def expect_it!
|
13
|
+
expect(subject)
|
14
|
+
end
|
15
|
+
|
16
|
+
def expect_it_safe
|
17
|
+
if block_given?
|
18
|
+
safe_lambda = lambda do
|
19
|
+
begin
|
20
|
+
self.subject
|
21
|
+
rescue Exception
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
ExpectItExpectationTarget.new(self, safe_lambda)
|
26
|
+
else
|
27
|
+
ExpectItSafeExpectationTarget.new(self)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def expect_it_safe!
|
32
|
+
result = begin
|
33
|
+
self.subject
|
34
|
+
rescue Exception
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
38
|
+
expect(result)
|
39
|
+
end
|
40
|
+
|
41
|
+
def expect_its(method)
|
42
|
+
ExpectItsExpectationTarget.new(self, method)
|
43
|
+
end
|
44
|
+
|
45
|
+
def expect_its!(method)
|
46
|
+
expect(subject.send(method))
|
47
|
+
end
|
48
|
+
|
49
|
+
class ExpectItExpectationTarget
|
50
|
+
attr_accessor :context, :subject
|
51
|
+
|
52
|
+
def initialize(context, subject = nil)
|
53
|
+
self.context = context
|
54
|
+
self.subject = subject
|
55
|
+
end
|
56
|
+
|
57
|
+
def to(matcher)
|
58
|
+
context.expect(get_subject).to(matcher)
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_not(matcher)
|
62
|
+
context.expect(get_subject).to_not(matcher)
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def get_subject
|
68
|
+
subject || context.subject
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
class ExpectItSafeExpectationTarget < ExpectItExpectationTarget
|
73
|
+
private
|
74
|
+
|
75
|
+
def get_subject
|
76
|
+
begin
|
77
|
+
subject || context.subject
|
78
|
+
rescue Exception
|
79
|
+
nil
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class ExpectItsExpectationTarget < ExpectItExpectationTarget
|
85
|
+
attr_accessor :method
|
86
|
+
|
87
|
+
def initialize(context, method)
|
88
|
+
super(context)
|
89
|
+
self.method = method
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def get_subject
|
95
|
+
context.subject.send(method)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rspec/expect_it/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rspec-expect_it"
|
8
|
+
spec.version = RSpec::ExpectIt::VERSION
|
9
|
+
spec.authors = ["Thomas Drake-Brockman"]
|
10
|
+
spec.email = ["thom@sfedb.com"]
|
11
|
+
spec.description = "Provides expect_it helpers for RSpec."
|
12
|
+
spec.summary = "Provides a expect_it helpers for RSpec."
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^spec/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "rspec", ">= 2.14.0"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RSpec::ExpectIt::Helpers do
|
4
|
+
describe "expect_it" do
|
5
|
+
describe "equalivalence" do
|
6
|
+
subject { Object.new }
|
7
|
+
|
8
|
+
specify { expect_it.to eq subject }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "lazy evaluation" do
|
12
|
+
before { @value = 0 }
|
13
|
+
|
14
|
+
subject { @value = 1 }
|
15
|
+
|
16
|
+
specify { expect_it.to eq (@value + 1) }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "unsaftey" do
|
20
|
+
subject { raise Exception }
|
21
|
+
|
22
|
+
specify { expect{expect_it.to be nil}.to raise_error(Exception) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "expect_it!" do
|
27
|
+
describe "equalivalence" do
|
28
|
+
subject { Object.new }
|
29
|
+
|
30
|
+
specify { expect_it!.to eq subject }
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "unlazy evaluation" do
|
34
|
+
before { @value = 0 }
|
35
|
+
|
36
|
+
subject { @value = 1 }
|
37
|
+
|
38
|
+
specify { expect_it!.to eq @value }
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "unsaftey" do
|
42
|
+
subject { raise Exception }
|
43
|
+
|
44
|
+
specify { expect{expect_it!.to be nil}.to raise_error(Exception) }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "expect_it{}" do
|
49
|
+
describe "equalivalence" do
|
50
|
+
before { @value = 0 }
|
51
|
+
|
52
|
+
subject { @value += 1 }
|
53
|
+
|
54
|
+
specify { expect_it{}.to be_a Proc }
|
55
|
+
specify { expect_it{}.to change{@value}.by(1) }
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "unsaftey" do
|
59
|
+
subject { raise Exception }
|
60
|
+
|
61
|
+
specify { expect{ expect_it{}.to_not change{0} }.to raise_error(Exception) }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "expect_it_safe" do
|
66
|
+
describe "equalivalence" do
|
67
|
+
subject { Object.new }
|
68
|
+
|
69
|
+
specify { expect_it_safe.to eq subject }
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "lazy evaluation" do
|
73
|
+
before { @value = 0 }
|
74
|
+
|
75
|
+
subject { @value = 1 }
|
76
|
+
|
77
|
+
specify { expect_it_safe.to eq (@value + 1) }
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "saftey" do
|
81
|
+
subject { raise Exception }
|
82
|
+
|
83
|
+
specify { expect_it_safe.to eq nil }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "expect_it_safe!" do
|
88
|
+
describe "equalivalence" do
|
89
|
+
subject { Object.new }
|
90
|
+
|
91
|
+
specify { expect_it_safe!.to eq subject }
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "unlazy evaluation" do
|
95
|
+
before { @value = 0 }
|
96
|
+
|
97
|
+
subject { @value = 1 }
|
98
|
+
|
99
|
+
specify { expect_it_safe!.to eq @value }
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "saftey" do
|
103
|
+
subject { raise Exception }
|
104
|
+
|
105
|
+
specify { expect_it_safe!.to eq nil }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "expect_it_safe{}" do
|
110
|
+
describe "equalivalence" do
|
111
|
+
before { @value = 0 }
|
112
|
+
|
113
|
+
subject { @value += 1 }
|
114
|
+
|
115
|
+
specify { expect_it_safe{}.to be_a Proc }
|
116
|
+
specify { expect_it_safe{}.to change{@value}.by(1) }
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "saftey" do
|
120
|
+
before { @value = 0 }
|
121
|
+
|
122
|
+
subject { raise Exception }
|
123
|
+
|
124
|
+
specify { expect{ expect_it_safe{}.to_not change{0} }.to_not raise_error(Exception) }
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-expect_it
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Thomas Drake-Brockman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-28 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.14.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.14.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Provides expect_it helpers for RSpec.
|
70
|
+
email:
|
71
|
+
- thom@sfedb.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .rspec
|
78
|
+
- .ruby-gemset
|
79
|
+
- .ruby-version
|
80
|
+
- .travis.yml
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- lib/rspec/expect_it.rb
|
86
|
+
- lib/rspec/expect_it/helpers.rb
|
87
|
+
- lib/rspec/expect_it/version.rb
|
88
|
+
- rspec-expect_it.gemspec
|
89
|
+
- spec/rspec/expect_it/helpers_spec.rb
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
homepage: ''
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.1.11
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Provides a expect_it helpers for RSpec.
|
115
|
+
test_files:
|
116
|
+
- spec/rspec/expect_it/helpers_spec.rb
|
117
|
+
- spec/spec_helper.rb
|