mackarel 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a876a6ccfa611381011f04602f493d657034fca
4
- data.tar.gz: 95bf290db7928b83348729c8e700830b33c1adba
3
+ metadata.gz: ba8d3cddea2ae2293a123036d42f174ee25aeb69
4
+ data.tar.gz: ca4e02890c971a163a268c97584c5b084581835f
5
5
  SHA512:
6
- metadata.gz: dc34f92ca95d8a854eb05c7cb2843ab40155bbfcc601f05c93d60127ec8061e837c70a369d6014e7f4002c0608cbc75a87ae469edd23968d2e2b5229c03cfbf8
7
- data.tar.gz: 6ea8ca19c4e98f05fe5b8630fd5500c8e7864404f5148f959800302de4b683c94a03b1c1a876339923e164bd8dd3ddfd665c91b06b4ec125102fe8e0111fb624
6
+ metadata.gz: a0d72af7c7de0dc816758a57b8a17cdbf342de2313293ad61c62052dd12d30b0f0df9c3050d129f34ce440e36ed7a53e3730f61197dd24ed8fd29a5e154995fc
7
+ data.tar.gz: cac06af1748818c04fe572736e04b886854eb53ccc792d7efa21e4fc863f747681a7a7d767820cecbd0901644612b8b0bdc8f1f939f9a0594410441c11c67614
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
  /tmp/
10
10
 
11
11
  *.gem
12
+ /flymd.*
data/README.md CHANGED
@@ -18,15 +18,23 @@ Or install it yourself as:
18
18
 
19
19
  $ gem install mackarel
20
20
 
21
- In your spec/spec_helper.rb file add
21
+ In your `spec/spec_helper.rb` or `spec/rails_helper.rb` file add:
22
22
 
23
23
  ```ruby
24
- config.include Mackarel
24
+ RSpec.configure { |c| config.include Mackarel }
25
+ ```
26
+
27
+ If you want to use [FactoryGirl](https://github.com/thoughtbot/factory_girl) as the backend for creating assets, add also:
28
+
29
+ ```ruby
30
+ Mackarel.config { |c| c.factory = FactoryGirl }
25
31
  ```
26
32
 
27
33
  ## Usage
28
34
 
29
- Mackarel allows you to write acceptance tests in Rails in a readable way without having to deal with things like Cucumber. It uses feature tests with RSpec, Factorygirl as the factory for models, and generally follows my setup.
35
+ Mackarel allows you to write acceptance tests in Rails in a readable way without having to deal with things like Cucumber.
36
+
37
+ It uses feature tests with RSpec. It can use Factorygirl as the factory for models, and Capybara for website testing.
30
38
 
31
39
  You can do things like:
32
40
 
@@ -50,7 +58,92 @@ RSpec.feature "Visiting the homepage" do
50
58
  end
51
59
  ```
52
60
 
53
- ### TODO: Document all helpers
61
+ ### What are all the things I can do?
62
+
63
+ #### Yielding
64
+
65
+ ```ruby
66
+ given {}
67
+ when_i {}
68
+ and_also {}
69
+ and_i {}
70
+ then_i {}
71
+ ```
72
+
73
+ These just yield. They are used to increase readibility:
74
+
75
+ ```ruby
76
+ RSpec.feature "Visiting admin page" do
77
+ scenario "It authenticates" do
78
+ given { username = "user" }
79
+ and_also { pass = "pass" }
80
+
81
+ when_i { visit admin_page_path }
82
+ and_i { login_with(username, pass) }
83
+
84
+ then_i { expect(page).to have_http_status(200) }
85
+ end
86
+ end
87
+ ```
88
+
89
+ #### Create objects
90
+
91
+ ```ruby
92
+ create(what, *args, **kwargs, &blk)
93
+ when_there_exists_a(what, *args, **kwargs, &blk)
94
+ when_there_exists_an(what, *args, **kwargs, &blk)
95
+ and_there_exists_a(what, *args, **kwargs, &blk)
96
+ and_there_exists_an(what, *args, **kwargs, &blk)
97
+ ```
98
+
99
+ These generate objects. By default, they use `Mackarel::BasicFactory`
100
+ to do so, but you can change that to use Factorygirl with
101
+ `Mackarel.config.factory = Mackarel::FactoryGirl`, or create your own. See later in this README to see how.
102
+
103
+
104
+ Create and friends figure out what you want to call the created
105
+ object: by default, it uses the "what", by converting it to a string,
106
+ downcasing it, and "underscore-ing" it. Also, l You can pass option
107
+ `called:` to change that name. They also return the created object. If
108
+ you pass `called: nil`, they don't create any instance variable.
109
+
110
+ The `what`, `*args` and `*kwargs` are passed as is to the factory.
111
+
112
+ For example:
113
+ ```
114
+ RSpec.feature "Visiting widget page" do
115
+ scenario "lists all widgets" do
116
+ when_i { create Widget, name: "first" }
117
+ and_there_exist_a Widget, name: "second"
118
+
119
+ and_i { visit admin_page_path }
120
+
121
+ then_i { can_see "first" }
122
+ and_i { can_see "second" }
123
+ end
124
+ end
125
+ ```
126
+
127
+ #### Create lists
128
+ ```ruby
129
+ create_a_list_of(n, what, *args, **kwargs, &blk)
130
+ and_there_exist(n, what, *args, **kwargs, &blk)
131
+ when_there_exist(n, what, *args, **kwargs, &blk)
132
+ ```
133
+
134
+ You can also generate lists of objects with one call. To do that, use `create_a_list_of` or one of its aliases. Pass how many objects you want in the list as the first parameter:
135
+
136
+ ```
137
+ RSpec.feature "Visiting widget page" do
138
+ scenario "lists all widgets" do
139
+ when_there_exist 5, Widget, name: "widget"
140
+ and_i { visit admin_page_path }
141
+
142
+ i_find ".widget", count: 5
143
+ end
144
+ end
145
+ ```
146
+
54
147
 
55
148
  ## Development
56
149
 
@@ -6,7 +6,6 @@ module Mackarel
6
6
  expect(current_path).to eq path
7
7
  end
8
8
 
9
-
10
9
  def i_can_see(something)
11
10
  expect(page).to have_content(something)
12
11
  end
data/lib/mackarel/core.rb CHANGED
@@ -4,33 +4,42 @@ module Mackarel
4
4
  yield
5
5
  end
6
6
 
7
- def factory
8
- Mackarel.config.factory
9
- end
10
-
11
- def when_there_exists_a(what, *args, **options)
12
- called = options.delete(:called) || what.to_s.underscore.tr("/", "_")
7
+ def create_a(what, *args, called: what, **options)
13
8
  asset = factory.create(what, *args, **options)
14
- instance_variable_set("@#{called}", asset)
9
+ if called
10
+ called = called.to_s.underscore.tr("/", "_")
11
+ instance_variable_set("@#{called}", asset)
12
+ end
15
13
  yield(asset) if block_given?
14
+ asset
16
15
  end
17
16
 
18
- def when_there_exist(number, what, *args, **options)
19
- called = options.delete(:called) || "#{what.to_s.underscore.tr("/", "_")}_list"
17
+ def create_a_list_of(number, what, *args, called: "#{what}_list", **options)
20
18
  asset = factory.create_list(what, number, *args, **options)
21
- instance_variable_set("@#{called}", asset)
19
+ if called
20
+ called = called.underscore.tr("/", "_")
21
+ instance_variable_set("@#{called}", asset)
22
+ end
22
23
  yield(asset) if block_given?
24
+ asset
25
+ end
26
+
27
+ def factory
28
+ Mackarel.config.factory
23
29
  end
24
30
 
25
31
  alias and_i when_i
26
32
  alias and_also when_i
27
33
  alias given when_i
34
+ alias then_i when_i
28
35
 
29
- alias when_there_exists_an when_there_exists_a
30
- alias and_there_exists_a when_there_exists_a
31
- alias and_there_exists_an when_there_exists_a
36
+ alias when_there_exists_a create_a
37
+ alias when_there_exists_an create_a
38
+ alias and_there_exists_a create_a
39
+ alias and_there_exists_an create_a
32
40
 
33
- alias and_there_exist when_there_exist
41
+ alias and_there_exist create_a_list_of
42
+ alias when_there_exist create_a_list_of
34
43
 
35
44
  end
36
45
  end
@@ -1,3 +1,3 @@
1
1
  module Mackarel
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mackarel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paolo Gianrossi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-24 00:00:00.000000000 Z
11
+ date: 2017-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler