rspec-has 0.1.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 +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/README.md +73 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/rspec/has.rb +39 -0
- data/lib/rspec/has/version.rb +5 -0
- data/rspec-has.gemspec +25 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2ab3be708c9aebea2f07480ab74d42445cc1d8ec
|
4
|
+
data.tar.gz: 572a7a3cec1afbb402c5e698560a0943eab816fa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4d1e93454177b1609e8fffc48e6df1dac27eecc7636c5f228f7f7a5cc6c5e280783482946b53b3423cab72c1e2da881319e7a5eafc19ccbbaec4b6d5613407a8
|
7
|
+
data.tar.gz: fb1e6eacd4e5bbf5719c6c6d5e0bca394e9d23a815a0685691a63c58e4b3d12c5f05edf8ca08fc84eed913e4c78ff8564fdda8e8cd2a4e7f8ae86600ea1cef72
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# Rspec::Has
|
2
|
+
|
3
|
+
[](https://gemnasium.com/d-unseductable/rspec-will_be_expected)
|
4
|
+
[](http://badge.fury.io/rb/rspec-will_be_expected)
|
5
|
+
[](https://travis-ci.org/d-unseductable/rspec-will_be_expected)
|
6
|
+
|
7
|
+
Designed to prettify one-liners when you have block expectations for subject.
|
8
|
+
|
9
|
+
Creates an alias `RSpec::Core::MemoizedHelpers.has` to `expect { subject }`
|
10
|
+
|
11
|
+
Simple to use:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
class SimplePrinter
|
15
|
+
def initialize
|
16
|
+
print 'Printer is ready'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
This goes to
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
it { has.to output('Printer is ready').to_stdout }
|
25
|
+
```
|
26
|
+
|
27
|
+
instead of
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
specify { expect { subject }.to output('Printer is ready').to_stdout }
|
31
|
+
```
|
32
|
+
|
33
|
+
For more complicated cases:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
describe UserFactory do
|
37
|
+
subject { UserFactory.create_user }
|
38
|
+
|
39
|
+
it { has.to change(User, :count).by(1) }
|
40
|
+
it { has.to output.to_stdout }
|
41
|
+
|
42
|
+
context 'with database issues' do
|
43
|
+
it { has.to output.to_stderr }
|
44
|
+
it { has.to raise_error }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
This change allows to DRY up, prettify and make specs even more readable.
|
50
|
+
|
51
|
+
## Installation
|
52
|
+
|
53
|
+
Add this line to your application's Gemfile:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
gem 'rspec-has'
|
57
|
+
```
|
58
|
+
|
59
|
+
And then execute:
|
60
|
+
|
61
|
+
$ bundle
|
62
|
+
|
63
|
+
Or install it yourself as:
|
64
|
+
|
65
|
+
$ gem install rspec-has
|
66
|
+
|
67
|
+
## Contributing
|
68
|
+
|
69
|
+
1. Fork it ( https://github.com/d-unseductable/rspec-has/fork )
|
70
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
71
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
72
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
73
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rspec/has"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/rspec/has.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rspec/has/version'
|
2
|
+
require 'rspec/core'
|
3
|
+
|
4
|
+
module RSpec
|
5
|
+
module Has
|
6
|
+
# Wraps the `subject` in `expect` with block to make it the target
|
7
|
+
# of an expectation.
|
8
|
+
# Designed to easily use expectations with blocks for one-liners.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
|
12
|
+
# describe UserFactory do
|
13
|
+
# subject { UserFactory.create_user }
|
14
|
+
#
|
15
|
+
# it { has.to change(User.count).by(1) }
|
16
|
+
# it { has.to output.to_stdout }
|
17
|
+
#
|
18
|
+
# context 'with database issues' do
|
19
|
+
# it { has.to output.to_stderr }
|
20
|
+
# it { has.to raise_error }
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# @see #subject
|
25
|
+
# @see #should
|
26
|
+
# @see #is_expected
|
27
|
+
#
|
28
|
+
# @note This only works if you are using rspec-expectations.
|
29
|
+
def has
|
30
|
+
expect { subject }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
RSpec.configure do |config|
|
36
|
+
config.include(RSpec::Has)
|
37
|
+
end
|
38
|
+
|
39
|
+
RSpec::Core::MemoizedHelpers.send(:include, RSpec::Has)
|
data/rspec-has.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rspec/has/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rspec-has"
|
8
|
+
spec.version = Rspec::Has::VERSION
|
9
|
+
spec.authors = ["Dmitry Gritsay"]
|
10
|
+
spec.email = ["unseductable@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{One-liner for block expectations}
|
13
|
+
spec.description = %q{One-liner for block expectations}
|
14
|
+
spec.homepage = "https://github.com/d-unseductable/rspec-has"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "rspec", "~> 3.0"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-has
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dmitry Gritsay
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-01 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: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.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.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: One-liner for block expectations
|
56
|
+
email:
|
57
|
+
- unseductable@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- lib/rspec/has.rb
|
71
|
+
- lib/rspec/has/version.rb
|
72
|
+
- rspec-has.gemspec
|
73
|
+
homepage: https://github.com/d-unseductable/rspec-has
|
74
|
+
licenses: []
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.4.5
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: One-liner for block expectations
|
96
|
+
test_files: []
|