ember-konacha-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +203 -0
  6. data/Rakefile +1 -0
  7. data/ember-konacha-rails.gemspec +26 -0
  8. data/lib/ember/konacha/rails.rb +9 -0
  9. data/lib/ember/konacha/rails/version.rb +7 -0
  10. data/lib/generators/ember_konacha/base_helper.rb +15 -0
  11. data/lib/generators/ember_konacha/controller_spec_generator.rb +82 -0
  12. data/lib/generators/ember_konacha/helper_spec_generator.rb +25 -0
  13. data/lib/generators/ember_konacha/install_generator.rb +298 -0
  14. data/lib/generators/ember_konacha/model_spec_generator.rb +25 -0
  15. data/lib/generators/ember_konacha/templates/konacha_config.js.coffee +16 -0
  16. data/lib/generators/ember_konacha/templates/sinon_mvc_mocks.js +141 -0
  17. data/lib/generators/ember_konacha/templates/spec_helper.js.coffee +69 -0
  18. data/lib/generators/ember_konacha/templates/specs/app/router_spec.js.coffee +7 -0
  19. data/lib/generators/ember_konacha/templates/specs/app/store_spec.js.coffee +10 -0
  20. data/lib/generators/ember_konacha/templates/specs/controller/array_controller_spec.js.coffee.erb +23 -0
  21. data/lib/generators/ember_konacha/templates/specs/controller/base_controller_spec.js.coffee.erb +19 -0
  22. data/lib/generators/ember_konacha/templates/specs/controller/object_controller_spec.js.coffee.erb +17 -0
  23. data/lib/generators/ember_konacha/templates/specs/helper_spec.js.coffee.erb +9 -0
  24. data/lib/generators/ember_konacha/templates/specs/model_spec.js.coffee.erb +17 -0
  25. data/lib/generators/ember_konacha/templates/specs/view_spec.js.coffee.erb +15 -0
  26. data/lib/generators/ember_konacha/templates/vendor/sinon.js +4223 -0
  27. data/lib/generators/ember_konacha/templates/views/application/index.html.slim +2 -0
  28. data/lib/generators/ember_konacha/templates/views/layouts/application.html.slim +9 -0
  29. data/lib/generators/ember_konacha/view_spec_generator.rb +25 -0
  30. metadata +131 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 59080e2ad04da84928d83f08cad96ceef3fc0af7
4
+ data.tar.gz: 5e73f9a3edd49bb7d42f36ee2c98e4456b5eec9e
5
+ SHA512:
6
+ metadata.gz: 84c49116c93ab27703179324260c6e17f52aaffbfcde0c0339d0bfdc61be3163688b018092da2fe21a3056eae0f63bb772c106111053718ebe484e192041e9d0
7
+ data.tar.gz: 2dbcf67cd4141d73c7fecf7fc58fc2bb97c9442322c2c3ae63c28c9d182c35fcf0b5c18821afc714a86f3ca60b22eac3943e58c644b2e378ea4a45b4a2c3201c
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ember-konacha-rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kristian Mandrup
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,203 @@
1
+ # Ember Konacha generators for Rails
2
+
3
+ Generators to help setup an [ember-rails](https://github.com/emberjs/ember-rails) app with [konacha](https://github.com/jfirebaugh/konacha) testing.
4
+
5
+ PS: Still young and under development... Please help improve it :)
6
+
7
+ ## What?
8
+
9
+ This gem has the stated goal of making it _easy_ to setup a good testing infrastructure for testing your *Ember-Rails* apps.
10
+
11
+ An `install` generator is included for initial infrastructure setup!
12
+
13
+ Configures your Ember app with *Konacha* using a Javascript driver (poltergeist for PhantomJS by default). Adds the basic Konacha infrastructure so you can start writing tests/specs.
14
+
15
+ Can generate *Konacha* spec-skeletons for:
16
+
17
+ * models
18
+ * controllers
19
+ * views
20
+ * helpers
21
+
22
+ Please help provide more skeleton generators or improve the existing ones!!! :)
23
+
24
+ ## Installation
25
+
26
+ Add this line to your application's Gemfile:
27
+
28
+ gem 'ember-konacha-rails', github: 'kristianmandrup/ember-konacha-rails'
29
+
30
+ And then execute:
31
+
32
+ $ bundle
33
+
34
+ Or (in the near future) install it yourself (from rubygems) as:
35
+
36
+ $ gem install ember-konacha-rails
37
+
38
+
39
+ To see if the generators are installed:
40
+
41
+ $ rails g
42
+
43
+ Note: or use `$ bundle exec rails g` (to execute in context of current bundled environment)
44
+
45
+ ```
46
+ ...
47
+
48
+ EmberKonacha:
49
+ ember_konacha:controller_spec
50
+ ember_konacha:helper_spec
51
+ ember_konacha:install
52
+ ember_konacha:model_spec
53
+ ember_konacha:view_spec
54
+
55
+ ...
56
+ ```
57
+
58
+ ## Usage
59
+
60
+ Install basic Konacha infrastructure
61
+
62
+ $ bundle exec rails g ember_konacha:install
63
+
64
+ Files that should be generated
65
+
66
+ ```
67
+ vendor/assets/javascripts/sinon.js
68
+
69
+ spec/javascripts/spec_helper.js.coffee
70
+ spec/javascripts/support/sinon_mvc_mocks.js.coffee
71
+ spec/javascripts/support/koncha_config.js.coffee
72
+
73
+ spec/javascripts/app/router_spec.js.coffee
74
+ spec/javascripts/app/store_spec.js.coffee
75
+ ```
76
+
77
+ ### Run examples
78
+
79
+ *Clean run (default settings)*
80
+
81
+ $ rails g ember_konacha:install
82
+ gemfile konacha
83
+ gemfile poltergeist
84
+ create spec/javascripts/spec_helper.js.coffee
85
+ create spec/javascripts/support/konacha_config.js.coffee
86
+ create spec/javascripts/support/sinon_mvc_mocks.js
87
+ Trying to download sinon.js (http://sinonjs.org/releases/sinon-1.6.js) ...
88
+ vendor assets/javascripts/sinon.js
89
+ create spec/javascripts/app/store_spec.js.coffee
90
+ create spec/javascripts/app/router_spec.js.coffee
91
+ gsub app/assets/javascripts/application.js.coffee
92
+ append app/assets/javascripts/application.js.coffee
93
+ ================================================================================
94
+ Note: poltergeist requires you have installed PhantomJS headless JS driver.
95
+
96
+ via Homebrew:
97
+
98
+ brew install phantomjs
99
+
100
+ MacPorts:
101
+
102
+ sudo port install phantomjs
103
+
104
+ See https://github.com/jonleighton/poltergeist
105
+
106
+ *Install generator was run previously*
107
+
108
+ ```
109
+ $ rails g ember_konacha:install
110
+ identical spec/javascripts/spec_helper.js.coffee
111
+ identical spec/javascripts/support/konacha_config.js.coffee
112
+ identical spec/javascripts/support/sinon_mvc_mocks.js
113
+ identical spec/javascripts/app/store_spec.js.coffee
114
+ identical spec/javascripts/app/router_spec.js.coffee
115
+ gsub app/assets/javascripts/application.js.coffee
116
+ append app/assets/javascripts/application.js.coffee
117
+ ```
118
+
119
+ Now run Konacha!
120
+
121
+ $ bundle exec rake konacha:run
122
+
123
+ See more run options at https://github.com/jfirebaugh/konacha
124
+
125
+ Note: make sure that the following is at the end of your `application.js.coffee` file:
126
+
127
+ ```javascript
128
+ window.App = Ember.Application.create LOG_TRANSITIONS: true
129
+
130
+ # Defer App readiness until it should be advanced for either
131
+ # testing or production.
132
+ App.deferReadiness()
133
+ ```
134
+
135
+ (or similar for pure javascript)
136
+
137
+ The basic test setup/configuration can be found in `support/koncha_config.js.coffee` and `spec_helper.js.coffee` files.
138
+
139
+ The `spec_helper` initializes the app explicitly using `App.advanceReadiness()` within `Ember.run` in the `beforeEach` closure. To run your app in the browser, while also allowing for testing, you need to explicitly call `App.advanceReadiness()` when your DOM is ready.
140
+
141
+ To see install options, run:
142
+
143
+ $ rails g ember_konacha:install --help
144
+
145
+ Note: To avoid having to `bundle exec` install the gem in your current system gem repository, using `gem install ember_konacha` (when this is an official gem!).
146
+
147
+ ### Generate Controller spec
148
+
149
+ Use the `--type` or `-t` option to specify type of controller (will try to auto-determine otherwise)
150
+
151
+ $ rails g ember_konacha:controller_spec login -t base
152
+
153
+ `spec/javascripts/controllers/login_controller_spec.js.coffee`
154
+
155
+ $ rails g ember_konacha:controller User --type object
156
+
157
+ `spec/javascripts/controllers/user_controller_spec.js.coffee`
158
+
159
+ $ rails g ember_konacha:controller_spec Users -t array
160
+
161
+ `spec/javascripts/controllers/user_controller_spec.js.coffee`
162
+
163
+ $ rails g ember_konacha:controller_spec Users
164
+
165
+ Will autodetect that users is a plural form of user and assume you have an array (resource) controller.
166
+
167
+ $ rails g ember_konacha:helper_spec persons
168
+
169
+ Will generate an object controller, since persons is not a valid plural form!
170
+
171
+ ### Generate Model spec
172
+
173
+ $ rails g ember_konacha:model_spec user
174
+
175
+ `spec/javascripts/models/user_spec.js.coffee`
176
+
177
+ ### Generate View spec
178
+
179
+ $ bundle exec rails g ember_konacha:view_spec NewUser
180
+
181
+ `spec/javascripts/views/new_user_view_spec.js.coffee`
182
+
183
+ ### Generate Helper spec
184
+
185
+ $ rails g ember_konacha:model_spec gravitation
186
+
187
+ `spec/javascripts/helpers/gravitation_helper_spec.js.coffee`
188
+
189
+ ## Sinon notice
190
+
191
+ The install generator will attempt to download sinon.js, first via httparty and then try via curl. On any exception it will fall back to just copying _sinon-1.6.0.js_.
192
+
193
+ Read more on [http://sinonjs.org/] for mocking, stubbing and creating test spies ;)
194
+
195
+ ## Contributing
196
+
197
+ Please help make it easier for developers tp get started using *Test Driven Development* (or BDD) for Ember with Rails.
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
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ember/konacha/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ember-konacha-rails"
8
+ spec.version = Ember::Konacha::Rails::VERSION
9
+ spec.authors = ["Kristian Mandrup"]
10
+ spec.email = ["kmandrup@gmail.com"]
11
+ spec.description = %q{Generate Konacha spec infrastructure for your Ember-Rails apps}
12
+ spec.summary = %q{Generate Konacha infrastructure for Ember}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rails", ">= 3.1"
22
+ spec.add_dependency "httparty", ">= 0.9"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ end
@@ -0,0 +1,9 @@
1
+ require "ember/konacha/rails/version"
2
+
3
+ module Ember
4
+ module Konacha
5
+ module Rails
6
+ # Your code goes here...
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ module Ember
2
+ module Konacha
3
+ module Rails
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ module EmberKonacha
2
+ module BaseHelper
3
+ def spec_target
4
+ target_file File.join(folder, "#{file_name}_spec.js.coffee")
5
+ end
6
+
7
+ def target_file path
8
+ File.join target_dir, path
9
+ end
10
+
11
+ def target_dir
12
+ "spec/javascripts/app/"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,82 @@
1
+ require 'active_support'
2
+ require 'generators/ember_konacha/base_helper'
3
+
4
+ module EmberKonacha
5
+ module Generators
6
+ class ControllerSpecGenerator < Rails::Generators::NamedBase
7
+ class_option :type, type: :string, aliases: ['t'],
8
+ desc: 'The type of controller to test',
9
+ banner: 'controller type: (array, object, base)'
10
+
11
+
12
+ source_root File.expand_path('../templates', __FILE__)
13
+
14
+ def create_controller
15
+ say "Creating #{type_name} controller spec", :green
16
+ template "specs/controller/#{type}_controller_spec.js.coffee.erb", spec_target
17
+ end
18
+
19
+ protected
20
+
21
+ def type_name
22
+ article = case type.to_sym
23
+ when :array, :object
24
+ "an"
25
+ else
26
+ "a"
27
+ end
28
+ "#{article} #{type}"
29
+ end
30
+
31
+ def validate_type!
32
+ unless valid_type? type
33
+ raise "Invalid Type, must be one of: #{valid_types}, was: #{type}"
34
+ end
35
+ end
36
+
37
+ include EmberKonacha::BaseHelper
38
+
39
+ def folder
40
+ 'controllers'
41
+ end
42
+
43
+ def model_name
44
+ "App.#{class_name}"
45
+ end
46
+
47
+ def array_controller_name
48
+ "App.#{class_name.pluralize}Controller"
49
+ end
50
+
51
+ def controller_name
52
+ "App.#{class_name}Controller"
53
+ end
54
+
55
+ def valid_type?
56
+ valid_types.include? type.to_s
57
+ end
58
+
59
+ def valid_types
60
+ %w{array object base}
61
+ end
62
+
63
+ def type
64
+ @type ||= resolved_type || options[:type]
65
+ end
66
+
67
+ def resolved_type
68
+ if options[:type].blank?
69
+ return is_plural?(name) ? 'array' : 'object'
70
+ end
71
+ end
72
+
73
+ def is_plural? str
74
+ str.singularize.pluralize == str
75
+ end
76
+
77
+ def is_singular? str
78
+ str.pluralize.singularize == str
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,25 @@
1
+ require 'generators/ember_konacha/base_helper'
2
+
3
+ module EmberKonacha
4
+ module Generators
5
+ class HelperSpecGenerator < Rails::Generators::NamedBase
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ def create_model
9
+ template "specs/helper_spec.js.coffee.erb", spec_target
10
+ end
11
+
12
+ protected
13
+
14
+ include EmberKonacha::BaseHelper
15
+
16
+ def folder
17
+ 'helpers'
18
+ end
19
+
20
+ def helper_name
21
+ "App.#{class_name}Helper"
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,298 @@
1
+ module EmberKonacha
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ class_option :sinon, type: :string, default: '1.6.0',
5
+ desc: 'Sinon version to get',
6
+ banner: 'Sinon version'
7
+
8
+ class_option :driver, type: :string, default: 'poltergeist',
9
+ desc: 'Javascript driver to use',
10
+ banner: 'Javascript driver'
11
+
12
+ class_option :with_index, type: :boolean, default: false,
13
+ desc: 'Generate default view files for single page app',
14
+ banner: 'Generate html view (index.html)'
15
+
16
+ source_root File.expand_path('../templates', __FILE__)
17
+
18
+ def do_validations
19
+ validate_driver!
20
+ validate_sinon_version!
21
+ end
22
+
23
+ def add_gems
24
+ unless has_gem? 'konacha'
25
+ gem 'konacha', group: [:development, :test]
26
+ end
27
+
28
+ has_gem?(js_driver) ? skip_driver : gem(js_driver, group: [:development, :test])
29
+
30
+ unless has_gem?('coffee-rails') || !coffee?
31
+ gem 'coffee-rails'
32
+ end
33
+ end
34
+
35
+ def create_infra_files
36
+ infra_files.each do |name|
37
+ begin
38
+ coffee_template name
39
+ rescue
40
+ js_template name
41
+ end
42
+ end
43
+ end
44
+
45
+ def create_vendor_files
46
+ return if has_sinon_file?
47
+
48
+ require 'httparty'
49
+
50
+ sinon_content = get_remote_file :sinon, sinon_version
51
+
52
+ return if has_file? sinon_file_path
53
+
54
+ if sinon_content.blank?
55
+ fallback_sinon!
56
+ end
57
+
58
+ vendor(sinon_path, sinon_content)
59
+
60
+ rescue Exception => e
61
+ say e.message, :red
62
+ say %Q{Sinon URI access/download error: #{@uri}.
63
+ Using sinon-1.6.js supplied by this gem ;)}
64
+ fallback_sinon!
65
+ end
66
+
67
+ def fallback_sinon!
68
+ template 'vendor/sinon.js', 'vendor/assets/javascripts/sinon.js'
69
+ end
70
+
71
+ def create_spec_files
72
+ spec_files.each do |name|
73
+ spec_template name
74
+ end
75
+ end
76
+
77
+ def add_pre
78
+ return unless has_file? Rails.root.join(coffee_manifest_file)
79
+
80
+ # ensure App is prefixed with window namespace!
81
+ gsub_file coffee_manifest_file, /[^\.]App =/ do |match|
82
+ match << "window.App ="
83
+ end
84
+
85
+ append_to_file coffee_manifest_file do
86
+ 'App.deferReadiness()'
87
+ end
88
+ end
89
+
90
+ def create_view_files
91
+ return unless with_index?
92
+
93
+ copy_file 'spec/views/layouts/application.html.slim', 'app/views/layouts/application.html.slim'
94
+ copy_file 'spec/views/application/index.html.slim', 'app/views/application/index.html.slim'
95
+ end
96
+
97
+
98
+ def post_install_notice
99
+ return if skipped_driver?
100
+
101
+ say nice(js_driver_notice) , :green
102
+ end
103
+
104
+ protected
105
+
106
+ def skip_driver
107
+ @skipped_driver = true
108
+ end
109
+
110
+ def skipped_driver?
111
+ @skipped_driver
112
+ end
113
+
114
+ def nice text
115
+ border + text
116
+ end
117
+
118
+ def border width = 80
119
+ @border ||= "=" * width + "\n"
120
+ end
121
+
122
+ def coffee?
123
+ true
124
+ end
125
+
126
+ def has_sinon_file?
127
+ @has_sinon ||= has_file? sinon_file_path
128
+ end
129
+
130
+ def has_file? path
131
+ File.exist?(path) && !blank_file?(sinon_file_path)
132
+ end
133
+
134
+ def blank_file? path
135
+ File.open(path).read.blank?
136
+ end
137
+
138
+ def sinon_file_path
139
+ Rails.root.join('vendor', sinon_path)
140
+ end
141
+
142
+ def sinon_path
143
+ "assets/javascripts/sinon.js"
144
+ end
145
+
146
+ def js_driver_notice
147
+ case js_driver.to_sym
148
+ when :poltergeist
149
+ %q{Note: poltergeist requires you have installed PhantomJS headless JS driver.
150
+
151
+ via Homebrew:
152
+
153
+ brew install phantomjs
154
+
155
+ MacPorts:
156
+
157
+ sudo port install phantomjs
158
+
159
+ See https://github.com/jonleighton/poltergeist
160
+ }
161
+ else
162
+ %q{Note: Install a suitable Javascript driver for headless js testing.
163
+
164
+ Google V8:
165
+
166
+ gem install therubyracer
167
+
168
+ Mozilla Rhino (JRuby only) :
169
+
170
+ gem install therubyrhino
171
+ }
172
+ end
173
+ end
174
+
175
+ def has_gem? name
176
+ gemfile_content =~ /gem\s+('|")#{name}/
177
+ end
178
+
179
+ def gemfile_content
180
+ @gemfile_content ||= gemfile.read
181
+ end
182
+
183
+ def gemfile
184
+ @gemfile ||= File.open Rails.root.join('Gemfile'), 'r'
185
+ end
186
+
187
+ def sinon_version
188
+ @sinon_version ||= options[:sinon]
189
+ end
190
+
191
+ def validate_sinon_version!
192
+ unless sinon_version =~ /\d\.\d\.\d/
193
+ say "Invalid sinon version format, must be of the form: x.y.z, f.ex 1.5.2, was: #{sinon_version}", :red
194
+ end
195
+ end
196
+
197
+ def with_index?
198
+ options[:with_index]
199
+ end
200
+
201
+ def coffee_manifest_file
202
+ 'app/assets/javascripts/application.js.coffee'
203
+ end
204
+
205
+ def validate_driver!
206
+ unless valid_driver? js_driver
207
+ say "Invalid javascript driver #{js_driver}, must be one of: #{valid_drivers}" , :red
208
+ end
209
+ end
210
+
211
+ def js_driver
212
+ options[:driver] || 'poltergeist'
213
+ end
214
+
215
+ def valid_driver? name
216
+ valid_drivers.include? name.to_s
217
+ end
218
+
219
+ def valid_drivers
220
+ %w{poltergeist selenium}
221
+ end
222
+
223
+ def spec_template name
224
+ src_file = File.join 'specs/app', name.to_s
225
+ target_file = File.join 'app', name.to_s
226
+ template coffee_filename(src_file), coffee_target_file(target_file)
227
+ end
228
+
229
+ def spec_files
230
+ [:store_spec, :router_spec]
231
+ end
232
+
233
+ def get_remote_file name, version = nil
234
+ url = version_it remote_uri[name.to_sym], version
235
+ @uri = URI url
236
+ say "Trying to download sinon.js (#{@uri}) ..."
237
+ response = HTTParty.get @uri
238
+
239
+ response.code != "404" ? result.body : nil
240
+
241
+ rescue Exception => e
242
+ empty_directory "vendor/assets/javascripts"
243
+ command = "curl #{@uri} -o vendor/#{sinon_path}"
244
+ %x[curl #{@uri} -o vendor/#{sinon_path}]
245
+ end
246
+
247
+ def version_it uri, version = nil
248
+ return uri if !version
249
+ uri.sub /VERSION/, version
250
+ end
251
+
252
+ def remote_uri
253
+ {
254
+ sinon: 'http://sinonjs.org/releases/sinon-VERSION.js'
255
+ }
256
+ end
257
+
258
+ def infra_files
259
+ [:spec_helper, :konacha_config, :sinon_mvc_mocks]
260
+ end
261
+
262
+ def coffee_template name
263
+ template coffee_filename(name), coffee_target_file(name)
264
+ end
265
+
266
+ def js_template name
267
+ template js_filename(name), js_target_file(name)
268
+ end
269
+
270
+ def js_target_file name
271
+ File.join 'spec/javascripts', js_filename(resolved_target name)
272
+ end
273
+
274
+ def coffee_target_file name
275
+ File.join 'spec/javascripts', coffee_filename(resolved_target name)
276
+ end
277
+
278
+ def resolved_target name
279
+ resolve_map[name.to_sym] || name
280
+ end
281
+
282
+ def resolve_map
283
+ {
284
+ sinon_mvc_mocks: 'support/sinon_mvc_mocks',
285
+ konacha_config: 'support/konacha_config'
286
+ }
287
+ end
288
+
289
+ def js_filename name
290
+ "#{name}.js"
291
+ end
292
+
293
+ def coffee_filename name
294
+ "#{name}.js.coffee"
295
+ end
296
+ end
297
+ end
298
+ end