rspec-non-deterministic-let 0.0.1 → 0.1.0
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 +4 -4
- data/README.md +103 -4
- data/lib/rspec/non_deterministic_let/helpers.rb +38 -2
- data/lib/rspec/non_deterministic_let/version.rb +1 -1
- 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: cea4fb4fbdbf5a9379120496fbc73d880af94536
|
4
|
+
data.tar.gz: 6367cbad8e85b5d3cc0f14aba2e8d04ff6eb5b3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d29c201b0c3b877c30411de04e2e6c6f4eb0b75a343f05e3e08b2f15d1da8db2cd447d6e298607d131a1eb2468628d4bc0f7489b0a7c9c732c7cb9f941304ad
|
7
|
+
data.tar.gz: b3e1fc0be30949f5e844528ce4e81036d446d3c13d72b82524fd2a830fc4af4eb66ab2ecce01be162accb40d23dc85d17e2369d093e0decc96588178d6879759
|
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
# Rspec::
|
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/rspec/non/deterministic/let`. To experiment with that code, run `bin/console` for an interactive prompt.
|
1
|
+
# Rspec::NonDeterministicLet
|
4
2
|
|
3
|
+
The aim of this gem is easy and intuitive writing with multi precondition specs.
|
5
4
|
|
6
5
|
## Installation
|
7
6
|
|
@@ -21,7 +20,107 @@ Or install it yourself as:
|
|
21
20
|
|
22
21
|
## Usage
|
23
22
|
|
24
|
-
|
23
|
+
### How to use your project
|
24
|
+
|
25
|
+
#### Rails
|
26
|
+
|
27
|
+
Please add spec/rails_helper.rb
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'rspec/actioncheck'
|
31
|
+
```
|
32
|
+
|
33
|
+
#### Other
|
34
|
+
|
35
|
+
Please add spec/spec_helper.rb
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
require 'rspec/actioncheck'
|
39
|
+
```
|
40
|
+
|
41
|
+
### Simple case
|
42
|
+
|
43
|
+
You can write that code in spec.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
RSpec.describe 'Some test'do
|
47
|
+
nd_let(:some_state) { 1 }
|
48
|
+
nd_let(:some_state) { 2 }
|
49
|
+
|
50
|
+
nd_let_context :some_state do
|
51
|
+
it 'some_state = 1 or 2' do
|
52
|
+
expect(some_state).to be >= 1
|
53
|
+
expect(some_state).to be <= 2
|
54
|
+
end
|
55
|
+
it 'some_state only 1 or 2' do
|
56
|
+
expect(some_state).not_to be < 1
|
57
|
+
expect(some_state).not_to be > 2
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
It is same as this code. (but context message is different)
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
RSpec.describe 'Some test without this gem'do
|
67
|
+
|
68
|
+
shared_examples 'some_state is 1 or 2' do
|
69
|
+
it 'some_state = 1 or 2' do
|
70
|
+
expect(some_state).to be >= 1
|
71
|
+
expect(some_state).to be <= 2
|
72
|
+
end
|
73
|
+
it 'some_state only 1 or 2' do
|
74
|
+
expect(some_state).not_to be < 1
|
75
|
+
expect(some_state).not_to be > 2
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'some_state = 1' do
|
80
|
+
let(:some_state) { 1 }
|
81
|
+
include_examples 'some_state is 1 or 2'
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'some_state = 2' do
|
85
|
+
let(:some_state) { 1 }
|
86
|
+
include_examples 'some_state is 1 or 2'
|
87
|
+
end
|
88
|
+
end
|
89
|
+
```
|
90
|
+
|
91
|
+
I think that before one is more intuitive.
|
92
|
+
|
93
|
+
`spec/rspec/examples_spec.rb` contain these examples.
|
94
|
+
|
95
|
+
### Description
|
96
|
+
|
97
|
+
If you want to description with `nd_let` then you can set description using by second argument.
|
98
|
+
|
99
|
+
```
|
100
|
+
RSpec.describe 'Some test use by description' do
|
101
|
+
nd_let(:some_state, 'some_state = 1') { 1 }
|
102
|
+
nd_let(:some_state, 'some_state = 2') { 2 }
|
103
|
+
|
104
|
+
nd_let_context :some_state do
|
105
|
+
it 'some_state = 1 or 2' do
|
106
|
+
expect(some_state).to be >= 1
|
107
|
+
expect(some_state).to be <= 2
|
108
|
+
end
|
109
|
+
it 'some_state only 1 or 2' do
|
110
|
+
expect(some_state).not_to be < 1
|
111
|
+
expect(some_state).not_to be > 2
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
```
|
116
|
+
|
117
|
+
This example is exactry same as `Some test without this gem` case.
|
118
|
+
|
119
|
+
|
120
|
+
### nd_let!
|
121
|
+
|
122
|
+
You can use `nd_let!`.
|
123
|
+
The effect of 'nd_let!' is same as `let!` for `let`
|
25
124
|
|
26
125
|
## Development
|
27
126
|
|
@@ -3,9 +3,13 @@ module RSpec
|
|
3
3
|
module Helpers
|
4
4
|
module ClassMethods
|
5
5
|
def nd_let_context(nd_let_name, *args, &example_group_block)
|
6
|
-
send(nd_let_name).each do |let_options|
|
6
|
+
send(__nd_let_state_name(nd_let_name)).each do |let_options|
|
7
7
|
context(let_options[:description], *args) do
|
8
|
-
|
8
|
+
if let_options[:is_exclamation]
|
9
|
+
let!(nd_let_name, &let_options[:block])
|
10
|
+
else
|
11
|
+
let(nd_let_name, &let_options[:block])
|
12
|
+
end
|
9
13
|
self.module_exec(&example_group_block)
|
10
14
|
end
|
11
15
|
end
|
@@ -25,6 +29,38 @@ module RSpec
|
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|
32
|
+
|
33
|
+
def nd_let(nd_let_name, description=nil, &let_block)
|
34
|
+
__update_let_state(nd_let_name, description, let_block, false)
|
35
|
+
end
|
36
|
+
|
37
|
+
def nd_let!(nd_let_name, description=nil, &let_block)
|
38
|
+
__update_let_state(nd_let_name, description, let_block, true)
|
39
|
+
end
|
40
|
+
|
41
|
+
def __update_let_state(nd_let_name, description, let_block, is_exclamation)
|
42
|
+
nd_let = 'nd_let'
|
43
|
+
nd_let += '!' if is_exclamation
|
44
|
+
|
45
|
+
nd_let_state_name = __nd_let_state_name(nd_let_name)
|
46
|
+
|
47
|
+
begin
|
48
|
+
let_blocks = send(nd_let_state_name)
|
49
|
+
description ||= "#{nd_let}:#{nd_let_name} \##{let_blocks.size + 1}"
|
50
|
+
self.define_singleton_method(nd_let_state_name) do ||
|
51
|
+
let_blocks + [{block: let_block, description: description, is_exclamation: is_exclamation}]
|
52
|
+
end
|
53
|
+
rescue NoMethodError
|
54
|
+
description ||= "#{nd_let}:#{nd_let_name} \##{1}"
|
55
|
+
self.define_singleton_method(nd_let_state_name) do ||
|
56
|
+
[{block: let_block, description: description, is_exclamation: is_exclamation}]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def __nd_let_state_name(nd_let_name)
|
62
|
+
"__nd_let_state_#{nd_let_name.to_s}".to_sym
|
63
|
+
end
|
28
64
|
end
|
29
65
|
end
|
30
66
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-non-deterministic-let
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuta Hinokuma
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|