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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb600b2f24a47896b1bafcb90dd19903a4cf3c98
4
- data.tar.gz: fe8481a4118ca712b7f28a410c8a4386ad5b7c8e
3
+ metadata.gz: cea4fb4fbdbf5a9379120496fbc73d880af94536
4
+ data.tar.gz: 6367cbad8e85b5d3cc0f14aba2e8d04ff6eb5b3c
5
5
  SHA512:
6
- metadata.gz: bbf85bbafbb3c314239961919eba2db6dbd4bc5624b86733d535c27dd5e1c1bae461e8f5151a89ba11943d2dd6e656494a1cff6ebd89bf1225aafbb10e372c3b
7
- data.tar.gz: 876beaf7858c0568c220fa3a8803432d34f857c615b703710d06848358d022bfa63476e9b3124e6ed1633b75d4f946525477d34b21341dc357be4ad064ecbfd0
6
+ metadata.gz: 2d29c201b0c3b877c30411de04e2e6c6f4eb0b75a343f05e3e08b2f15d1da8db2cd447d6e298607d131a1eb2468628d4bc0f7489b0a7c9c732c7cb9f941304ad
7
+ data.tar.gz: b3e1fc0be30949f5e844528ce4e81036d446d3c13d72b82524fd2a830fc4af4eb66ab2ecce01be162accb40d23dc85d17e2369d093e0decc96588178d6879759
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
- # Rspec::Non::Deterministic::Let
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
- Write usage instructions here
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
- let(nd_let_name, &let_options[:block])
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
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module NonDeterministicLet
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  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.1
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-10 00:00:00.000000000 Z
11
+ date: 2017-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler