rspecz 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rspecz/aliases/behave.rb +8 -0
- data/lib/rspecz/aliases/make.rb +9 -0
- data/lib/rspecz/behave.rb +13 -0
- data/lib/rspecz/contexts.rb +91 -0
- data/lib/rspecz/lets.rb +37 -0
- data/lib/rspecz/subjects.rb +17 -0
- data/lib/rspecz/version.rb +3 -0
- data/lib/rspecz/with.rb +188 -0
- data/lib/rspecz.rb +9 -0
- data/rspecz.gemspec +27 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8b437acabae389beb51eda1e28f49ed9f19502536b6dbcdbfacdb0ed7f3b144c
|
4
|
+
data.tar.gz: e83aba1baed93bd0d1208f22386103bbd791b87854e90f86101fc42a308aefe0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: abdac6c31c319e1d6a0ebd1538ad686a67588c056fd6b524098f7cdde3d1344e4a58ce6875d8e5ee61b2dae07ee15078016625c48c4ce3beafe036a274862f0f
|
7
|
+
data.tar.gz: 17b20b3397efe8951ac991a9fde7362b4b5ac1ed105e2059ba870be831637fca8fa57804bd6b499b429d121d22e3d5d1e48220f04d550ad4d963ad347c9b714e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at app.zenn@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rspecz (0.1.1)
|
5
|
+
rspec (>= 3.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.3)
|
11
|
+
rake (10.5.0)
|
12
|
+
rspec (3.8.0)
|
13
|
+
rspec-core (~> 3.8.0)
|
14
|
+
rspec-expectations (~> 3.8.0)
|
15
|
+
rspec-mocks (~> 3.8.0)
|
16
|
+
rspec-core (3.8.0)
|
17
|
+
rspec-support (~> 3.8.0)
|
18
|
+
rspec-expectations (3.8.1)
|
19
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
20
|
+
rspec-support (~> 3.8.0)
|
21
|
+
rspec-mocks (3.8.0)
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
+
rspec-support (~> 3.8.0)
|
24
|
+
rspec-support (3.8.0)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
bundler (~> 1.16)
|
31
|
+
rake (~> 10.0)
|
32
|
+
rspecz!
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Zenn
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# RSpecZ
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/RSpecZ`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rspecz'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install RSpecZ
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/RSpecZ. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the RSpecZ project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/RSpecZ/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rspecz"
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Core
|
3
|
+
module MemoizedHelpers
|
4
|
+
module ClassMethods
|
5
|
+
# TODO: あとで綺麗にリファクタリングする
|
6
|
+
# TODO: contexts のときに配列が空だったらエラーが出るようにする
|
7
|
+
|
8
|
+
def set_nil(name, description = nil, &block)
|
9
|
+
context description || "when #{name} is nil" do
|
10
|
+
let(name) { nil }
|
11
|
+
instance_exec(name, &block)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
alias_method :nil_context, :set_nil
|
15
|
+
|
16
|
+
def set_nils(*names, &block)
|
17
|
+
names.each do |name|
|
18
|
+
nil_context(name, &block)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
alias_method :nil_contexts, :set_nils
|
22
|
+
|
23
|
+
def set(name, value, description = nil, &block)
|
24
|
+
context description || "when #{name} is #{value}" do
|
25
|
+
let(name) { value }
|
26
|
+
instance_exec(name, value, &block)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
alias_method :value_context, :set
|
30
|
+
|
31
|
+
def set_values(name, *values, &block)
|
32
|
+
values.each do |value|
|
33
|
+
value_context(name, value, &block)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
alias_method :value_contexts, :set_values
|
37
|
+
|
38
|
+
def set_valid(name, value, description = nil, &block)
|
39
|
+
context description || "when #{name} is valid(#{value})" do
|
40
|
+
let(name) { value }
|
41
|
+
instance_exec(name, value, &block)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def set_invalid(name, value = 'invalid-value', description = nil, &block)
|
46
|
+
context description || "when #{name} is not valid(#{value})" do
|
47
|
+
let(name) { value }
|
48
|
+
instance_exec(name, value, &block)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
alias_method :invalid_context, :set_invalid
|
52
|
+
|
53
|
+
def set_invalids(name, *values, &block)
|
54
|
+
values.each do |value|
|
55
|
+
invalid_context(name, value, &block)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
alias_method :invalid_contexts, :set_invalids
|
59
|
+
|
60
|
+
def set_block(name, description = nil, &block)
|
61
|
+
continue_object = { name: name, descrioption: description, block: block, myobject: self }
|
62
|
+
def continue_object.spec(&block)
|
63
|
+
continue_object = self
|
64
|
+
self[:myobject].context self[:description] || "when #{self[:name]} is different" do
|
65
|
+
let(continue_object[:name]) { instance_eval(&continue_object[:block]) }
|
66
|
+
instance_exec(name, &block)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
continue_object
|
70
|
+
end
|
71
|
+
alias_method :block_context, :set_block
|
72
|
+
|
73
|
+
def set_missing(name, value = 'missing-value', description = nil, &block)
|
74
|
+
context description || "when #{name} is not exist(#{value})" do
|
75
|
+
let(name) { value }
|
76
|
+
instance_exec(name, &block)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
alias_method :nonexist_context, :set_missing
|
80
|
+
|
81
|
+
def set_context(name, &block)
|
82
|
+
context "when include context(#{name})" do
|
83
|
+
include_context name
|
84
|
+
instance_eval(&block)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
alias_method :with_context, :set_context
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/lib/rspecz/lets.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Core
|
3
|
+
module MemoizedHelpers
|
4
|
+
module ClassMethods
|
5
|
+
def string(*names)
|
6
|
+
__each_if_method_not_defined(names) do |name|
|
7
|
+
let(name) { "test-#{name}" }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_params(*array)
|
12
|
+
__each_if_method_not_defined(array) do |val|
|
13
|
+
let(val) { "test-#{val}" }
|
14
|
+
end
|
15
|
+
let(:with_nil) { false } unless __lib_method_defined?(:with_nil)
|
16
|
+
let(:params) {
|
17
|
+
array.each_with_object({}) do |elem, acc|
|
18
|
+
acc[elem] = send(elem) if send(:with_nil) || send(elem).present?
|
19
|
+
end
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def __each_if_method_not_defined(names)
|
26
|
+
names.each do |name|
|
27
|
+
yield(name) unless __lib_method_defined?(name)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def __lib_method_defined?(name)
|
32
|
+
RSpec::Core::MemoizedHelpers.module_for(self).method_defined?(name)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Core
|
3
|
+
module MemoizedHelpers
|
4
|
+
module ClassMethods
|
5
|
+
def subject_freezed(&block)
|
6
|
+
if RSpec::Core::MemoizedHelpers.module_for(self).method_defined?('now')
|
7
|
+
before(:each) { instance_eval { travel_to(now) } }
|
8
|
+
after(:each) { instance_eval { travel_back } }
|
9
|
+
subject(&block)
|
10
|
+
else
|
11
|
+
subject { raise RuntimeError.new('subject_freezed need you to define let(:now). Please define let(:now)') }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/rspecz/with.rb
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Core
|
3
|
+
module MemoizedHelpers
|
4
|
+
module ClassMethods
|
5
|
+
class WithContext
|
6
|
+
attr_accessor :name, :values, :description, :hint, :focused, :block, :myobject, :and_name, :and_block
|
7
|
+
|
8
|
+
def initialize(name, values, block, myobject)
|
9
|
+
@name, @values, @block, @myobject = name, values, block, myobject
|
10
|
+
end
|
11
|
+
|
12
|
+
def desc(description)
|
13
|
+
@description = description
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def hint(text)
|
18
|
+
@hint = text
|
19
|
+
end
|
20
|
+
|
21
|
+
def focused
|
22
|
+
@focused = true
|
23
|
+
end
|
24
|
+
|
25
|
+
def and(name, &block)
|
26
|
+
raise RuntimeError.new('You cannot set and two times! "and" method can use only one time in single with method.') unless @and_block.nil?
|
27
|
+
@and_name = name
|
28
|
+
@and_block = block
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def so(&block)
|
33
|
+
continue_object = self
|
34
|
+
continue_object_block = @block
|
35
|
+
# TODO: create description from block.source
|
36
|
+
if @values.length > 0
|
37
|
+
raise RuntimeError.new("Syntax error you cannot set description by 'desc' method when you have multiple values set.") if @values.length > 1 && @description
|
38
|
+
@values.each do |value|
|
39
|
+
context_text = @hint ? "when #{@name} is #{@hint}(#{value})" : "when #{@name} is #{value}"
|
40
|
+
|
41
|
+
spec_without_and = lambda do
|
42
|
+
let(continue_object.name) { value }
|
43
|
+
instance_exec(value, &block)
|
44
|
+
end
|
45
|
+
|
46
|
+
spec = @and_block.nil? ? spec_without_and : lambda do
|
47
|
+
context "and #{continue_object.and_name} is #{continue_object.__get_description(continue_object.and_block.source, 'and')}" do
|
48
|
+
let(continue_object.and_name) do
|
49
|
+
@super = super() if defined? super
|
50
|
+
instance_eval(&continue_object.and_block)
|
51
|
+
end
|
52
|
+
instance_exec(&spec_without_and)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
if @focused
|
57
|
+
@myobject.fcontext(context_text, &spec)
|
58
|
+
else
|
59
|
+
@myobject.context(context_text, &spec)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
else
|
63
|
+
context_text = @name ? "when #{@name} is #{__get_description(@block.source, 'with')}" : "prepare #{__get_description(@block.source, 'with')}"
|
64
|
+
|
65
|
+
spec_without_and = lambda do
|
66
|
+
if continue_object.name
|
67
|
+
let(continue_object.name) do
|
68
|
+
@super = super() if defined? super
|
69
|
+
instance_eval(&continue_object_block)
|
70
|
+
end
|
71
|
+
else
|
72
|
+
before { instance_eval(&continue_object_block) }
|
73
|
+
end
|
74
|
+
instance_exec(&block)
|
75
|
+
end
|
76
|
+
|
77
|
+
spec = @and_block.nil? ? spec_without_and : lambda do
|
78
|
+
context "and #{continue_object.and_name} is #{continue_object.__get_description(continue_object.and_block.source, 'and')}" do
|
79
|
+
let(continue_object.and_name) { instance_eval(&continue_object.and_block) }
|
80
|
+
instance_exec(&spec_without_and)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
if @focused
|
85
|
+
@myobject.fcontext(@description || context_text, &spec)
|
86
|
+
else
|
87
|
+
@myobject.context(@description || context_text, &spec)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# TODO: This method is temporary method. Need to implement proper logic in future .
|
93
|
+
def __get_description(text, method_name)
|
94
|
+
begin
|
95
|
+
text = text[text.index("#{method_name}")..-1]
|
96
|
+
bracket_start = text.index('{') || text.length
|
97
|
+
do_start = text.index('do') || text.length
|
98
|
+
|
99
|
+
start_word = bracket_start < do_start ? '{' : 'do'
|
100
|
+
end_word = start_word == '{' ? '}' : 'end'
|
101
|
+
|
102
|
+
start_index = [bracket_start, do_start].min + start_word.length
|
103
|
+
inline_bracket_start = start_index
|
104
|
+
next_end = 1
|
105
|
+
start_word_count = 0
|
106
|
+
|
107
|
+
loop do
|
108
|
+
next_end = text[inline_bracket_start..-1].index(end_word) || text.length
|
109
|
+
start_word_count += text[inline_bracket_start..inline_bracket_start+next_end].scan(start_word).length
|
110
|
+
start_word_count -= 1
|
111
|
+
# binding.pry
|
112
|
+
break if start_word_count < 0
|
113
|
+
inline_bracket_start += next_end + 1
|
114
|
+
end
|
115
|
+
|
116
|
+
text[start_index...inline_bracket_start+next_end].split("\n").last.strip
|
117
|
+
rescue => e
|
118
|
+
p 'Warning: rspecz with __get_description failed...'
|
119
|
+
'different'
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def with(name = nil, *values, &block) _with(name, nil, false, values, block); end
|
125
|
+
def fwith(name = nil, *values, &block) _with(name, nil, true, values, block); end
|
126
|
+
|
127
|
+
def with_valid(name = nil, *values, &block) _with(name, 'valid', false, values, block); end
|
128
|
+
alias_method :with_valids, :with_valid
|
129
|
+
|
130
|
+
def fwith_valid(name = nil, *values, &block) _with(name, 'valid', true, values, block); end
|
131
|
+
alias_method :fwith_valids, :fwith_valid
|
132
|
+
|
133
|
+
def with_invalid(name = nil, *values, &block) _with(name, 'invalid', false, values, block); end
|
134
|
+
alias_method :with_invalids, :with_invalid
|
135
|
+
|
136
|
+
def fwith_invalid(name = nil, *values, &block) _with(name, 'invalid', true, values, block); end
|
137
|
+
alias_method :fwith_invalids, :fwith_invalid
|
138
|
+
|
139
|
+
def with_missing(name = nil, *values, &block) _with(name, 'missing',false, values, block); end
|
140
|
+
alias_method :with_missings, :with_missing
|
141
|
+
|
142
|
+
def fwith_missing(name = nil, *values, &block) _with(name, 'missing',true, values, block); end
|
143
|
+
alias_method :fwith_missings, :fwith_missing
|
144
|
+
|
145
|
+
def with_nil(*names) _with_nil(names, false); end
|
146
|
+
alias_method :with_nils, :with_nil
|
147
|
+
|
148
|
+
def fwith_nil(*names) _with_nil(names, true); end
|
149
|
+
alias_method :fwith_nils, :fwith_nil
|
150
|
+
|
151
|
+
private
|
152
|
+
|
153
|
+
def _with(name, hint, focused, values, block)
|
154
|
+
with_context = WithContext.new(name, values, block, self)
|
155
|
+
with_context.hint(hint) if hint
|
156
|
+
with_context.focused if focused
|
157
|
+
with_context
|
158
|
+
end
|
159
|
+
|
160
|
+
def _with_nil(names, focused)
|
161
|
+
raise RuntimeError.new("Argument Error. You should set names.") if names.nil? || names.length == 0
|
162
|
+
|
163
|
+
continue_object = { names: names, focused: focused, myobject: self }
|
164
|
+
|
165
|
+
def continue_object.desc(text)
|
166
|
+
raise RuntimeError.new("Error. You cannot use desc with with_nil method.")
|
167
|
+
end
|
168
|
+
|
169
|
+
def continue_object.so(&block)
|
170
|
+
continue_object = self
|
171
|
+
continue_object[:names].each do |name|
|
172
|
+
spec = lambda do
|
173
|
+
let(name) { nil }
|
174
|
+
instance_exec(name, &block)
|
175
|
+
end
|
176
|
+
if continue_object[:focused]
|
177
|
+
self[:myobject].fcontext("When #{name} is nil", &spec)
|
178
|
+
else
|
179
|
+
self[:myobject].context("When #{name} is nil", &spec)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
continue_object
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
data/lib/rspecz.rb
ADDED
data/rspecz.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "rspecz/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rspecz"
|
8
|
+
spec.version = RSpecZ::VERSION
|
9
|
+
spec.authors = ["seteen"]
|
10
|
+
spec.email = ["app.zenn@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Provide functions for smart RSpec.}
|
13
|
+
spec.homepage = "https://github.com/seteen/RSpecZ"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_dependency 'rspec', '>= 3.0'
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspecz
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- seteen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-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.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.16'
|
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:
|
56
|
+
email:
|
57
|
+
- app.zenn@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- CODE_OF_CONDUCT.md
|
66
|
+
- Gemfile
|
67
|
+
- Gemfile.lock
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- lib/rspecz.rb
|
74
|
+
- lib/rspecz/aliases/behave.rb
|
75
|
+
- lib/rspecz/aliases/make.rb
|
76
|
+
- lib/rspecz/behave.rb
|
77
|
+
- lib/rspecz/contexts.rb
|
78
|
+
- lib/rspecz/lets.rb
|
79
|
+
- lib/rspecz/subjects.rb
|
80
|
+
- lib/rspecz/version.rb
|
81
|
+
- lib/rspecz/with.rb
|
82
|
+
- rspecz.gemspec
|
83
|
+
homepage: https://github.com/seteen/RSpecZ
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.7.6
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: Provide functions for smart RSpec.
|
107
|
+
test_files: []
|