contractinator 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -9
- data/lib/contractinator/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: ed606aefaecfff4239703067517b0e2495037758
|
4
|
+
data.tar.gz: 6a64d437ec0b6b153db93a25f6c83613ce81c025
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 299543f8aa70f979522e24a6842b8c08634917bb09e21484fc57f0070316ade14214bb5bc50360ccfa22c38461577ef7d5a7f63b3f4d3f8feb8d2b06add50dda
|
7
|
+
data.tar.gz: 3b5dc5509088f867cace9640cbece9b3e949eeeda4f020fb24eed42637d469c8a0bfb9ffd9acb44cdf037c70d50b5feff2f553e984ebcecf1a386bd781e8ef4c
|
data/README.md
CHANGED
@@ -18,7 +18,7 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
Then inform RSpec that you'd like to use contractinator by adding something like the following to your spec_helper.rb
|
20
20
|
|
21
|
-
```
|
21
|
+
```ruby
|
22
22
|
require 'contractinator'
|
23
23
|
|
24
24
|
RSpec.configure do |config|
|
@@ -47,7 +47,7 @@ There are several ways to document a provider's behavior. The easiest is to use
|
|
47
47
|
|
48
48
|
In the spec for a consumer, for example a rails controller, you might have
|
49
49
|
|
50
|
-
```
|
50
|
+
```ruby
|
51
51
|
it 'assigns a new entry' do
|
52
52
|
stipulate(Entry).must receive(:new).and_return(entry)
|
53
53
|
get :new
|
@@ -58,14 +58,14 @@ end
|
|
58
58
|
|
59
59
|
This sets the expectation that Entry.new will be called, and stubs it out to return `entry`. Now you should get a warning in your rspec output that looks like this:
|
60
60
|
|
61
|
-
```
|
61
|
+
```ruby
|
62
62
|
unfulfilled contract 'Entry.new -> entry'
|
63
63
|
at spec/controllers/entries_controller_spec.rb:45:in `block (3 levels) in <top (required)>'
|
64
64
|
```
|
65
65
|
|
66
66
|
The next step is to make sure that contract is fulfilled by something. So we'll switch over to the model spec
|
67
67
|
|
68
|
-
```
|
68
|
+
```ruby
|
69
69
|
describe '.new' do
|
70
70
|
it { agree(Entry, :new).will be_a(Entry) }
|
71
71
|
end
|
@@ -76,14 +76,14 @@ This calls new on Entry and asserts that it is_a Entry, and fulfills a contract
|
|
76
76
|
### Less straight-forward contracts
|
77
77
|
Not every contract in an application is so easy to specify. For example, a view spec which assigns a local variable has an agreement with a controller to assign that variable. Some other matchers available:
|
78
78
|
|
79
|
-
```
|
79
|
+
```ruby
|
80
80
|
assign_contract('entries#new', :entry, entry)
|
81
81
|
flash_contract('entries#create', :notice, 'Great Success!') if flash_enabled
|
82
82
|
```
|
83
83
|
|
84
84
|
In these two cases, the method both does the side effect (assigning a variable for a view spec or setting a flash message), and also creates a matching contract. There isn't a corresponding fulfillment matcher for anything else yet, so you have to fulfill them manually. I do this like so, in my controller spec:
|
85
85
|
|
86
|
-
```
|
86
|
+
```ruby
|
87
87
|
describe 'get :new' do
|
88
88
|
it { fulfills 'entries#new assign @entry' }
|
89
89
|
it do
|
@@ -95,16 +95,16 @@ end
|
|
95
95
|
### Free-form contracts
|
96
96
|
Sometimes I think of things that need a contract that I have no matchers for, and all I really want is a smart comment. I'm using this for a routing contract relationship now. In that case, you can do this:
|
97
97
|
|
98
|
-
```
|
98
|
+
```ruby
|
99
99
|
# this is a contract that might be created
|
100
100
|
# by a link in a view spec for example
|
101
|
-
|
101
|
+
contract("get / routes")
|
102
102
|
|
103
103
|
```
|
104
104
|
|
105
105
|
And fulfill it with
|
106
106
|
|
107
|
-
```
|
107
|
+
```ruby
|
108
108
|
it { fulfills('get / routes') }
|
109
109
|
```
|
110
110
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contractinator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ehren Murdick
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: exe
|
13
13
|
cert_chain: []
|
14
|
-
date: 2016-02-
|
14
|
+
date: 2016-02-19 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rspec
|