alfred_rails 0.0.1.alpha
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 +7 -0
- data/.gitignore +19 -0
- data/.travis.yml +20 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +209 -0
- data/Rakefile +5 -0
- data/alfred_rails.gemspec +45 -0
- data/app/assets/javascripts/alfred/sinon_adapter.js.coffee +35 -0
- data/app/assets/javascripts/alfred.js.coffee +61 -0
- data/bin/alfred +6 -0
- data/lib/alfred_rails/command_line.rb +62 -0
- data/lib/alfred_rails/configuration.rb +157 -0
- data/lib/alfred_rails/definition.rb +129 -0
- data/lib/alfred_rails/fixture_file.rb +70 -0
- data/lib/alfred_rails/mock.rb +14 -0
- data/lib/alfred_rails/rails.rb +14 -0
- data/lib/alfred_rails/registry.rb +84 -0
- data/lib/alfred_rails/request.rb +38 -0
- data/lib/alfred_rails/runner.rb +116 -0
- data/lib/alfred_rails/scenario.rb +99 -0
- data/lib/alfred_rails/scenario_dsl.rb +83 -0
- data/lib/alfred_rails/ui.rb +90 -0
- data/lib/alfred_rails/version.rb +3 -0
- data/lib/alfred_rails.rb +99 -0
- data/lib/generators/alfred/controller/controller_generator.rb +24 -0
- data/lib/generators/alfred/controller/templates/alfred.erb +7 -0
- data/lib/generators/alfred/install/install_generator.rb +85 -0
- data/lib/generators/alfred/install/templates/alfred_helper.erb +23 -0
- data/lib/tasks/alfred.rake +6 -0
- data/spec/command_line_spec.rb +64 -0
- data/spec/configuration_spec.rb +86 -0
- data/spec/definition_spec.rb +135 -0
- data/spec/fixture_file_spec.rb +60 -0
- data/spec/fixtures/database.yml +4 -0
- data/spec/generators/controller/controller_generator_spec.rb +23 -0
- data/spec/generators/install/install_generator_spec.rb +56 -0
- data/spec/javascripts/alfred/sinon_adapter_spec.js.coffee +33 -0
- data/spec/javascripts/alfred_spec.js.coffee +46 -0
- data/spec/javascripts/spec_helper.coffee +5 -0
- data/spec/mock_spec.rb +18 -0
- data/spec/registry_spec.rb +78 -0
- data/spec/request_spec.rb +32 -0
- data/spec/runner_spec.rb +179 -0
- data/spec/scenario_dsl_spec.rb +62 -0
- data/spec/scenario_spec.rb +24 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/support/application.rb +21 -0
- data/spec/support/controllers/api/v1/posts_controller.rb +14 -0
- data/spec/support/controllers/api/v1/users_controller.rb +14 -0
- data/spec/support/lib/response_proxy.rb +11 -0
- data/spec/support/models/post.rb +1 -0
- data/spec/support/models/user.rb +1 -0
- data/spec/support/rails.rb +14 -0
- data/spec/support/routes.rb +9 -0
- data/spec/support/schema.rb +16 -0
- data/spec/teaspoon_env.rb +14 -0
- data/spec/ui_spec.rb +72 -0
- metadata +316 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5aa092990a0c15473f2de135190053a555556beb
|
4
|
+
data.tar.gz: 4c733b4d2437fc8bcb064be5f7b6e0c45e4a8652
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 287ec639bca0ca48c0bf5f0690848f8888b271850856f86f6ad2c207a593925c966b16b515bbab5f481256d65a1e5cb807cf0252f292ee151020474485456309
|
7
|
+
data.tar.gz: a92f6780d2ee432c6ec1bf77c44d3db50ed9bf4b0caa89afed01e76f9cb7706231435fa3a4462cc5b4ac5e1fb93e4bdbdcb4c9cce7fa4d742f9889017b0f5041
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.9.3
|
4
|
+
- 2.0.0
|
5
|
+
- 2.1.1
|
6
|
+
- ruby-head
|
7
|
+
|
8
|
+
env:
|
9
|
+
- "RAILS_VERSION=3.1.0"
|
10
|
+
- "RAILS_VERSION=3.2.0"
|
11
|
+
- "RAILS_VERSION=4.0.0"
|
12
|
+
- "RAILS_VERSION=4.1.0"
|
13
|
+
- "RAILS_VERSION=master"
|
14
|
+
|
15
|
+
matrix:
|
16
|
+
allow_failures:
|
17
|
+
- env: "RAILS_VERSION=master"
|
18
|
+
- rvm: ruby-head
|
19
|
+
|
20
|
+
script: "bundle exec teaspoon && rake"
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Johan van Zonneveld
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,209 @@
|
|
1
|
+
## Alfred Rails
|
2
|
+
|
3
|
+
[][gem]
|
4
|
+
[][travis]
|
5
|
+
[][coveralls]
|
6
|
+
[][codeclimate]
|
7
|
+
[][gemnasium]
|
8
|
+
|
9
|
+
[gem]: https://rubygems.org/gems/alfred_rails
|
10
|
+
[travis]: http://travis-ci.org/jhnvz/alfred_rails
|
11
|
+
[coveralls]: https://coveralls.io/r/jhnvz/alfred_rails
|
12
|
+
[codeclimate]: https://codeclimate.com/github/jhnvz/alfred_rails
|
13
|
+
[gemnasium]: https://gemnasium.com/jhnvz/alfred_rails
|
14
|
+
|
15
|
+
Serves controller action responses under several conditions.
|
16
|
+
|
17
|
+
How it works
|
18
|
+
------------
|
19
|
+
|
20
|
+
Alfred creates fixture files of your controller responses so you can use them in your tests. Ideal if your app's client is build with a javascript framework and you want to test responses under several conditions.
|
21
|
+
|
22
|
+
Resources
|
23
|
+
------------
|
24
|
+
|
25
|
+
- [Installation](#installation)
|
26
|
+
- [Defining scenario's](#defining-scenarios)
|
27
|
+
- [Configuration](#configuration)
|
28
|
+
- [Javascript testing](#javascript-testing)
|
29
|
+
- [Guard](#guard)
|
30
|
+
|
31
|
+
Installation
|
32
|
+
------------
|
33
|
+
|
34
|
+
1. Add `gem 'alfred_rails'` to your Gemfile (inside test group).
|
35
|
+
2. Run `bundle install`.
|
36
|
+
3. Run `rails g alfred:install`.
|
37
|
+
|
38
|
+
Defining scenario's
|
39
|
+
------------
|
40
|
+
|
41
|
+
You can create empty definitions by running:
|
42
|
+
```
|
43
|
+
$ rails g alfred:controller api/v1/posts
|
44
|
+
```
|
45
|
+
|
46
|
+
Here's an example of a definition:
|
47
|
+
```ruby
|
48
|
+
# spec/alfreds/api/v1/posts_controller.rb
|
49
|
+
|
50
|
+
Alfred.define do
|
51
|
+
setup do
|
52
|
+
sign_in :user, create(:user)
|
53
|
+
end
|
54
|
+
|
55
|
+
controller Api::V1::PostsController do
|
56
|
+
scenario 'update post by manager' do
|
57
|
+
setup do
|
58
|
+
create(:post, :title => 'Alfred is awesome', :body => 'It saves me time')
|
59
|
+
end
|
60
|
+
|
61
|
+
patch :update, {
|
62
|
+
:format => :json,
|
63
|
+
:id => 1,
|
64
|
+
:post => {
|
65
|
+
:title => 'Alfred rocks!'
|
66
|
+
}
|
67
|
+
}
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
scenario 'update post by manager' do
|
72
|
+
controller Api::V1::PostsController
|
73
|
+
end
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
77
|
+
This will create a fixture file which you can use in your javascript tests at:
|
78
|
+
```
|
79
|
+
spec/javascripts/fixtures/api/v1/posts/update/update_by_manager.js
|
80
|
+
```
|
81
|
+
|
82
|
+
Configuration
|
83
|
+
------------
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
# spec/alfred_helper.rb
|
87
|
+
|
88
|
+
Alfred.configure do |config|
|
89
|
+
## Includes
|
90
|
+
config.include FactoryGirl::Syntax::Methods
|
91
|
+
config.include Devise::TestHelpers
|
92
|
+
|
93
|
+
## Setup
|
94
|
+
config.setup do
|
95
|
+
Apartment::Database.stub(:create).and_return(true)
|
96
|
+
end
|
97
|
+
|
98
|
+
## Mocking framework
|
99
|
+
config.mock_with :rspec
|
100
|
+
|
101
|
+
## Fixture path
|
102
|
+
config.fixture_path 'spec/javascripts/fixtures'
|
103
|
+
end
|
104
|
+
```
|
105
|
+
|
106
|
+
Configuration instructions
|
107
|
+
|
108
|
+
Javascript testing
|
109
|
+
------------
|
110
|
+
|
111
|
+
After defining and generating Alfred fixtures they are accessible in your JavaScript tests.
|
112
|
+
|
113
|
+
```coffeescript
|
114
|
+
# Get request response
|
115
|
+
Alfred.serve('posts_controller/update', 'update post by manager')
|
116
|
+
|
117
|
+
# Example of a test
|
118
|
+
describe 'PostModel', ->
|
119
|
+
|
120
|
+
describe '#update', ->
|
121
|
+
|
122
|
+
it 'should update model', ->
|
123
|
+
response = Alfred.serve('posts_controller/update', 'update post by manager')
|
124
|
+
@server = sinon.fakeServer.create()
|
125
|
+
|
126
|
+
@server.respondWith 'PATCH', 'posts/1', [200, { 'Content-Type': 'application/json' }, response]
|
127
|
+
|
128
|
+
@post.update()
|
129
|
+
@server.respond()
|
130
|
+
|
131
|
+
@post.updated().should.equal(true)
|
132
|
+
```
|
133
|
+
|
134
|
+
Implementation on this differs on which libraries you are using to test with. In the above example we're using SinonJS to create a fake server response.
|
135
|
+
|
136
|
+
### SinonJS adapter
|
137
|
+
|
138
|
+
```coffeescript
|
139
|
+
# Creates fake server and calls respondWith
|
140
|
+
Alfred.SinonAdapter.serve('posts_controller/update', 'update post by manager')
|
141
|
+
|
142
|
+
# Example of a test
|
143
|
+
describe 'PostModel', ->
|
144
|
+
|
145
|
+
describe '#update', ->
|
146
|
+
|
147
|
+
it 'should update model', ->
|
148
|
+
@server = Alfred.SinonAdapter.serve('posts_controller/update', 'update post by manager')
|
149
|
+
|
150
|
+
@post.update()
|
151
|
+
@server.respond()
|
152
|
+
|
153
|
+
@post.updated().should.equal(true)
|
154
|
+
```
|
155
|
+
|
156
|
+
### Using any other test adapter
|
157
|
+
|
158
|
+
By calling `Alfred.fetch` you can fetch a scenario object with meta data, such as path, request method etc. This can be useful when stubbing a request;
|
159
|
+
|
160
|
+
```coffeescript
|
161
|
+
Alfred.fetch('posts/update', 'update post by manager') # => Object
|
162
|
+
```
|
163
|
+
|
164
|
+
Guard
|
165
|
+
------------
|
166
|
+
|
167
|
+
Add the gem to your Gemfile (inside development group):
|
168
|
+
``` ruby
|
169
|
+
gem 'guard-alfred', :require => false
|
170
|
+
```
|
171
|
+
|
172
|
+
Add guard definition to your Guardfile by running this command:
|
173
|
+
```
|
174
|
+
$ guard init alfred
|
175
|
+
```
|
176
|
+
|
177
|
+
Make sure to put this block on top of your Guardfile so all fixtures are created before running tests.
|
178
|
+
```ruby
|
179
|
+
guard :alfred do
|
180
|
+
watch(%r{^app/controllers/(.+)\.rb$}) { |m| "spec/alfreds/#{m[1]}.rb" }
|
181
|
+
watch(%r{^spec/alfreds/(.+)\.rb$}) { |m| "spec/alfreds/#{m[1]}.rb" }
|
182
|
+
end
|
183
|
+
```
|
184
|
+
Please read [Guard usage doc](https://github.com/guard/guard#readme) for usage instructions.
|
185
|
+
|
186
|
+
Supported Ruby Versions
|
187
|
+
------------
|
188
|
+
|
189
|
+
This library is tested against Travis and aims to support the following Ruby
|
190
|
+
implementations:
|
191
|
+
|
192
|
+
* Ruby 1.9.3
|
193
|
+
* Ruby 2.0.0
|
194
|
+
* Ruby 2.1.1
|
195
|
+
|
196
|
+
Contributing
|
197
|
+
------------
|
198
|
+
|
199
|
+
1. Fork it
|
200
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
201
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
202
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
203
|
+
5. Create new Pull Request
|
204
|
+
|
205
|
+
Copyright
|
206
|
+
------------
|
207
|
+
|
208
|
+
Copyright (c) 2014 Johan van Zonneveld. See LICENSE for details.
|
209
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'alfred_rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "alfred_rails"
|
8
|
+
gem.version = Alfred::VERSION
|
9
|
+
gem.authors = ['Johan van Zonneveld', 'Arjen Oosterkamp']
|
10
|
+
gem.email = ['johan@vzonneveld.nl', 'mail@arjen.me']
|
11
|
+
gem.homepage = 'https://github.com/jhnvz/alfred_rails.git'
|
12
|
+
gem.summary = %q{Serves controller responses under several conditions.}
|
13
|
+
gem.description = %q{Alfred creates fixture files of your controller responses so you can use them in your tests. Ideal if your app's client is build with a javascript framework and you want to test responses under several conditions.}
|
14
|
+
gem.license = 'MIT'
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = ["alfred"]
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ['lib']
|
20
|
+
|
21
|
+
gem.add_development_dependency 'bundler', '>= 1.0.0'
|
22
|
+
gem.add_development_dependency 'rake'
|
23
|
+
gem.add_development_dependency 'coveralls'
|
24
|
+
gem.add_development_dependency 'rspec', '>= 2.3'
|
25
|
+
gem.add_development_dependency 'rspec-rails', '~> 2.0'
|
26
|
+
gem.add_development_dependency 'batman-rails'
|
27
|
+
gem.add_development_dependency 'sqlite3'
|
28
|
+
|
29
|
+
gem.add_development_dependency 'teaspoon'
|
30
|
+
gem.add_development_dependency 'coffee-script'
|
31
|
+
|
32
|
+
gem.add_dependency 'database_cleaner'
|
33
|
+
gem.add_dependency 'ruby-progressbar'
|
34
|
+
gem.add_dependency 'ammeter'
|
35
|
+
|
36
|
+
if RUBY_VERSION > '1.9.2'
|
37
|
+
gem.add_dependency 'rails', '>= 3.2.0'
|
38
|
+
else
|
39
|
+
gem.add_dependency 'rails', '>= 3.2.0', '< 4.0.0'
|
40
|
+
end
|
41
|
+
|
42
|
+
if File.exists?('UPGRADING')
|
43
|
+
gem.post_install_message = File.read("UPGRADING")
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class Alfred.SinonAdapter
|
2
|
+
|
3
|
+
###*
|
4
|
+
* Serves an Alfred response server.
|
5
|
+
* @action {String} Controller and action
|
6
|
+
* @name {String} Name of the scenario
|
7
|
+
*
|
8
|
+
* @example
|
9
|
+
* server = Alfred.SinonAdapter.serve('sessions/current', 'default')
|
10
|
+
* server.respond()
|
11
|
+
*
|
12
|
+
* @returns
|
13
|
+
* {Object} Sinon FakeServer
|
14
|
+
*
|
15
|
+
###
|
16
|
+
@serve: (action, name, path) ->
|
17
|
+
scenario = Alfred.fetch(action, name)
|
18
|
+
meta = scenario.meta
|
19
|
+
path ||= @_path(meta.path)
|
20
|
+
|
21
|
+
server = sinon.fakeServer.create()
|
22
|
+
server.respondWith meta.method, path, [meta.status, { 'Content-Type': meta.type }, scenario.response]
|
23
|
+
|
24
|
+
server
|
25
|
+
|
26
|
+
###*
|
27
|
+
* Makes sure the path is correct, without starting slash
|
28
|
+
* @path {String} Path to correct
|
29
|
+
*
|
30
|
+
###
|
31
|
+
@_path: (path) ->
|
32
|
+
if path[0] == '/'
|
33
|
+
path.slice(1, path.length)
|
34
|
+
else
|
35
|
+
path
|
@@ -0,0 +1,61 @@
|
|
1
|
+
class @Alfred
|
2
|
+
|
3
|
+
@scenarios: {}
|
4
|
+
|
5
|
+
###*
|
6
|
+
* Fetches an Alfred response.
|
7
|
+
* @action {String} Controller and action
|
8
|
+
* @name {String} Name of the scenario
|
9
|
+
*
|
10
|
+
* @example
|
11
|
+
* Alfred.fetch('sessions/current', 'default')
|
12
|
+
*
|
13
|
+
* @returns
|
14
|
+
* {Object} Scenario object
|
15
|
+
*
|
16
|
+
###
|
17
|
+
@fetch: (action, name) ->
|
18
|
+
@scenarios[action]?[@_name(name)]
|
19
|
+
|
20
|
+
###*
|
21
|
+
* Serves an Alfred response.
|
22
|
+
* @action {String} Controller and action
|
23
|
+
* @name {String} Name of the scenario
|
24
|
+
*
|
25
|
+
* @example
|
26
|
+
* Alfred.serve('sessions/current', 'default')
|
27
|
+
*
|
28
|
+
* @returns
|
29
|
+
* {String} Scenario response string
|
30
|
+
*
|
31
|
+
###
|
32
|
+
@serve: (action, name) ->
|
33
|
+
@fetch(action, name)?.response
|
34
|
+
|
35
|
+
###*
|
36
|
+
* Registers an Alfred response.
|
37
|
+
* @action {String} Controller and action
|
38
|
+
* @name {String} Name of the scenario
|
39
|
+
* @meta {Object} Meta data of the response
|
40
|
+
* @response {String} Scenario response
|
41
|
+
*
|
42
|
+
* @example
|
43
|
+
* Alfred.register({
|
44
|
+
* action: 'sessions/current',
|
45
|
+
* name: 'default',
|
46
|
+
* meta: { path: 'api/1/sessions', method: 'GET' },
|
47
|
+
* response: @response
|
48
|
+
* })
|
49
|
+
*
|
50
|
+
###
|
51
|
+
@register: (object) ->
|
52
|
+
@scenarios[object.action] ||= {}
|
53
|
+
@scenarios[object.action][object.name] = {
|
54
|
+
name: object.name
|
55
|
+
action: object.action
|
56
|
+
meta: object.meta
|
57
|
+
response: object.response
|
58
|
+
}
|
59
|
+
|
60
|
+
@_name: (name) ->
|
61
|
+
name.replace(/\s+/g, '_').toLowerCase()
|
data/bin/alfred
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
ENV["RAILS_ENV"] ||= 'test'
|
2
|
+
|
3
|
+
require "optparse"
|
4
|
+
|
5
|
+
module Alfred
|
6
|
+
class CommandLine
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@options = {}
|
10
|
+
@options[:files] = parse_options
|
11
|
+
|
12
|
+
load_rails!
|
13
|
+
|
14
|
+
require 'alfred_rails'
|
15
|
+
::Alfred.load!
|
16
|
+
|
17
|
+
::Alfred::Runner.new(@options[:files])
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# Add abort method in case input is aborted.
|
22
|
+
#
|
23
|
+
# :nocov:
|
24
|
+
def abort(message = nil)
|
25
|
+
STDOUT.print(message) if message
|
26
|
+
exit(1)
|
27
|
+
end
|
28
|
+
# :nocov:
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
##
|
33
|
+
# Parses the options and returns the files if present.
|
34
|
+
#
|
35
|
+
# === Returns
|
36
|
+
#
|
37
|
+
# [files (Array)] the files to run
|
38
|
+
#
|
39
|
+
def parse_options
|
40
|
+
options = {}
|
41
|
+
OptionParser.new do |options|
|
42
|
+
options.banner = "Usage: alfred [options] [files]\n"
|
43
|
+
|
44
|
+
options.on "-v", "--version", "Display the version.", proc {
|
45
|
+
STDOUT.print("#{Alfred::VERSION}\n")
|
46
|
+
exit
|
47
|
+
}
|
48
|
+
end.parse!
|
49
|
+
end
|
50
|
+
|
51
|
+
##
|
52
|
+
# Load Rails environment and Alfred.
|
53
|
+
#
|
54
|
+
# :nocov:
|
55
|
+
def load_rails!
|
56
|
+
load 'config/application.rb'
|
57
|
+
::Rails.application.initialize!
|
58
|
+
end
|
59
|
+
# :nocov:
|
60
|
+
|
61
|
+
end # CommandLine
|
62
|
+
end # Alfred
|
@@ -0,0 +1,157 @@
|
|
1
|
+
module Alfred
|
2
|
+
class Configuration
|
3
|
+
|
4
|
+
attr_accessor :config
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@config = {
|
8
|
+
:includes => [],
|
9
|
+
:setup => []
|
10
|
+
}
|
11
|
+
|
12
|
+
load_defaults!
|
13
|
+
end
|
14
|
+
|
15
|
+
##
|
16
|
+
# Set or get setup for each scenario.
|
17
|
+
#
|
18
|
+
# === Params
|
19
|
+
#
|
20
|
+
# [block (Block)] the block to perform
|
21
|
+
#
|
22
|
+
# === Example
|
23
|
+
#
|
24
|
+
# setup
|
25
|
+
# User.create(:name => 'John Doe')
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# setup #=> [Proc]
|
29
|
+
#
|
30
|
+
# === Returns
|
31
|
+
#
|
32
|
+
# [setup (Array)] array with blocks
|
33
|
+
#
|
34
|
+
def setup(&block)
|
35
|
+
return @config[:setup] unless block_given?
|
36
|
+
@config[:setup] << block
|
37
|
+
end
|
38
|
+
|
39
|
+
##
|
40
|
+
# Include modules.
|
41
|
+
#
|
42
|
+
# === Params
|
43
|
+
#
|
44
|
+
# [mod (Module)] the module to include
|
45
|
+
#
|
46
|
+
# === Example
|
47
|
+
#
|
48
|
+
# include Devise::TestHelpers
|
49
|
+
#
|
50
|
+
def include(mod)
|
51
|
+
@config[:includes] << mod
|
52
|
+
end
|
53
|
+
|
54
|
+
##
|
55
|
+
# Returns array of the modules to include.
|
56
|
+
#
|
57
|
+
# === Returns
|
58
|
+
#
|
59
|
+
# [modules (Array)] the modules to include
|
60
|
+
#
|
61
|
+
def includes
|
62
|
+
@config[:includes]
|
63
|
+
end
|
64
|
+
|
65
|
+
##
|
66
|
+
# Set or get the fixture path.
|
67
|
+
#
|
68
|
+
# === Params
|
69
|
+
#
|
70
|
+
# [path (String)] the path to set
|
71
|
+
#
|
72
|
+
# === Examples
|
73
|
+
#
|
74
|
+
# fixture_path('spec/javascript/fixtures')
|
75
|
+
# fixture_path #=> 'spec/javascript/fixtures'
|
76
|
+
#
|
77
|
+
# === Returns
|
78
|
+
#
|
79
|
+
# [path (String)] the fixture path
|
80
|
+
#
|
81
|
+
def fixture_path(path=nil)
|
82
|
+
return config[:fixture_path] if path.nil?
|
83
|
+
config[:fixture_path] = "#{::Rails.root}/#{path}"
|
84
|
+
end
|
85
|
+
|
86
|
+
##
|
87
|
+
# Set or get the test path.
|
88
|
+
#
|
89
|
+
# === Params
|
90
|
+
#
|
91
|
+
# [path (String)] the path to set
|
92
|
+
#
|
93
|
+
# === Examples
|
94
|
+
#
|
95
|
+
# test_path('spec')
|
96
|
+
# test_path #=> 'spec'
|
97
|
+
#
|
98
|
+
# === Returns
|
99
|
+
#
|
100
|
+
# [path (String)] the fixture path
|
101
|
+
#
|
102
|
+
def test_path(path=nil)
|
103
|
+
return config[:test_path] if path.nil?
|
104
|
+
config[:test_path] = path
|
105
|
+
end
|
106
|
+
|
107
|
+
##
|
108
|
+
# Set or get the mocking framework.
|
109
|
+
#
|
110
|
+
# === Params
|
111
|
+
#
|
112
|
+
# [framework (Symbol)] the mocking framework
|
113
|
+
#
|
114
|
+
# === Examples
|
115
|
+
#
|
116
|
+
# mock_with :rspec
|
117
|
+
# mock_with #=> :rspec
|
118
|
+
#
|
119
|
+
# === Returns
|
120
|
+
#
|
121
|
+
# [framework (Symbol)] mocking framework
|
122
|
+
#
|
123
|
+
def mock_with(framework=nil)
|
124
|
+
return config[:mock_with] if framework.nil?
|
125
|
+
config[:mock_with] = framework
|
126
|
+
end
|
127
|
+
|
128
|
+
private
|
129
|
+
|
130
|
+
##
|
131
|
+
# Wheter rspec is defined.
|
132
|
+
#
|
133
|
+
def rspec_defined?
|
134
|
+
defined?(RSpec)
|
135
|
+
end
|
136
|
+
|
137
|
+
##
|
138
|
+
# Loads defaults based on defined constants.
|
139
|
+
# It guesses fixture_path and mocking framework.
|
140
|
+
#
|
141
|
+
def load_defaults!
|
142
|
+
## Guess test path
|
143
|
+
@config[:test_path] = rspec_defined? ? "spec" : "test"
|
144
|
+
|
145
|
+
## Guess fixture_path
|
146
|
+
@config[:fixture_path] = "#{::Rails.root}/#{test_path}/javascripts/fixtures"
|
147
|
+
|
148
|
+
## Guess mocking framework
|
149
|
+
@config[:mock_with] = if rspec_defined?
|
150
|
+
:rspec
|
151
|
+
else
|
152
|
+
:test_unit
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
end # Configuration
|
157
|
+
end # Alfred
|