ember-konacha-rails 0.1.0 → 0.1.1

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: 59080e2ad04da84928d83f08cad96ceef3fc0af7
4
- data.tar.gz: 5e73f9a3edd49bb7d42f36ee2c98e4456b5eec9e
3
+ metadata.gz: 8b7440a8b9e2d5fa3b2be784ef9ce5e6774a5b3b
4
+ data.tar.gz: db2679be97f99263ae2e5612f09f7886bcb4dbbc
5
5
  SHA512:
6
- metadata.gz: 84c49116c93ab27703179324260c6e17f52aaffbfcde0c0339d0bfdc61be3163688b018092da2fe21a3056eae0f63bb772c106111053718ebe484e192041e9d0
7
- data.tar.gz: 2dbcf67cd4141d73c7fecf7fc58fc2bb97c9442322c2c3ae63c28c9d182c35fcf0b5c18821afc714a86f3ca60b22eac3943e58c644b2e378ea4a45b4a2c3201c
6
+ metadata.gz: 6000dacbf3deaa0f89334a1eb52008497397546f1c1324fef762f31814ed2795cf007f8ea040891c7ea41232ad977c39a7d7976a0f4b8d093779713347b327ae
7
+ data.tar.gz: 2cd178e88be693a03de798be0efc619a50580c15a1202d68d0d9ff49356376e3f1fffdd1a916b27f6d3d6d1b5b4a57b9a0c1eab19a5bec83c1f3099fee954fd1
data/README.md CHANGED
@@ -21,6 +21,17 @@ Can generate *Konacha* spec-skeletons for:
21
21
 
22
22
  Please help provide more skeleton generators or improve the existing ones!!! :)
23
23
 
24
+ ### More generators
25
+
26
+ You can find more generators/scaffolders as part of [ember-tools](https://github.com/rpflorence/ember-tools/)
27
+
28
+ [ember-i18n-rails](https://github.com/andrzejsliwa/ember-i18n-rails) or [here](https://github.com/kristianmandrup/ember-i18n-rails). Includes generators to configure and manage *i18n* with Ember and Rails.
29
+
30
+ ### Other Ember-Rails tools
31
+
32
+ * [page_wrapper](https://github.com/mathieul/page_wrapper)
33
+ * [elasticsearch](https://github.com/karmi/ember-data-elasticsearch)
34
+
24
35
  ## Installation
25
36
 
26
37
  Add this line to your application's Gemfile:
@@ -31,7 +42,7 @@ And then execute:
31
42
 
32
43
  $ bundle
33
44
 
34
- Or (in the near future) install it yourself (from rubygems) as:
45
+ Or install it yourself (from rubygems) as:
35
46
 
36
47
  $ gem install ember-konacha-rails
37
48
 
@@ -59,7 +70,7 @@ EmberKonacha:
59
70
 
60
71
  Install basic Konacha infrastructure
61
72
 
62
- $ bundle exec rails g ember_konacha:install
73
+ $ rails g ember_konacha:install
63
74
 
64
75
  Files that should be generated
65
76
 
@@ -144,6 +155,16 @@ To see install options, run:
144
155
 
145
156
  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
157
 
158
+ ## Guard Koncha config generator
159
+
160
+ To setup your project with Guard and execute koncha specs whenever your javascript assets change (default driver: poltergeist)
161
+
162
+ $ rails g ember_konacha:guard
163
+
164
+ To specify a specific js driver (selenium or webkit):
165
+
166
+ $ rails g ember_konacha:guard --driver wekbkit
167
+
147
168
  ### Generate Controller spec
148
169
 
149
170
  Use the `--type` or `-t` option to specify type of controller (will try to auto-determine otherwise)
@@ -1,7 +1,7 @@
1
1
  module Ember
2
2
  module Konacha
3
3
  module Rails
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,48 @@
1
+ module EmberKonacha
2
+ module GemHelper
3
+ def bundle_gems!
4
+ bundle_command 'install'
5
+ end
6
+
7
+ # File railties/lib/rails/generators/app_base.rb, line 241
8
+ def bundle_command(command)
9
+ say_status :run, "bundle #{command}"
10
+
11
+ # We are going to shell out rather than invoking Bundler::CLI.new(command)
12
+ # because `rails new` loads the Thor gem and on the other hand bundler uses
13
+ # its own vendored Thor, which could be a different version. Running both
14
+ # things in the same process is a recipe for a night with paracetamol.
15
+ #
16
+ # We use backticks and #print here instead of vanilla #system because it
17
+ # is easier to silence stdout in the existing test suite this way. The
18
+ # end-user gets the bundler commands called anyway, so no big deal.
19
+ #
20
+ # Thanks to James Tucker for the Gem tricks involved in this call.
21
+ print %x[#{Gem.ruby} -rubygems "#{ruby_gems}" #{command}]
22
+ end
23
+
24
+ def ruby_gems
25
+ Gem.bin_path('bundler', 'bundle')
26
+ end
27
+
28
+ def has_any_gem? *names
29
+ names.flatten.any? {|name| has_gem? name }
30
+ end
31
+
32
+ def has_all_gems? *names
33
+ names.flatten.all? {|name| has_gem? name }
34
+ end
35
+
36
+ def has_gem? name
37
+ gemfile_content =~ /gem\s+('|")#{name}/
38
+ end
39
+
40
+ def gemfile_content
41
+ @gemfile_content ||= gemfile.read
42
+ end
43
+
44
+ def gemfile
45
+ @gemfile ||= File.open Rails.root.join('Gemfile'), 'r'
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,138 @@
1
+ require 'generators/ember_konacha/gem_helper'
2
+
3
+ module EmberKonacha
4
+ module Generators
5
+ class GuardGenerator < Rails::Generators::Base
6
+ class_option :driver, type: :string, default: 'poltergeist',
7
+ desc: 'Konacha JS driver to use',
8
+ banner: 'Konacha JS driver'
9
+
10
+ TPL_PATH = File.expand_path('../templates', __FILE__)
11
+
12
+ source_root TPL_PATH
13
+
14
+ def add_guard_gem
15
+ return if has_all_gems? 'guard', 'guard-konacha'
16
+
17
+ gem 'guard' unless has_gem? 'guard'
18
+ gem 'guard-konacha' unless has_gem? 'guard-konacha'
19
+
20
+ if driver == 'webkit'
21
+ gem "capybara-webkit" unless has_gem? "capybara-webkit"
22
+ end
23
+
24
+ bundle_gems!
25
+
26
+ say "Notice: Please move the gem statements just appended to the Gemfile into a [:test, :development] group", :green
27
+ end
28
+
29
+ def create_guardfile
30
+ return if guard_file?
31
+ init_guard!
32
+ end
33
+
34
+ def guardfile_append_konacha_config
35
+ validate_driver!
36
+
37
+ unless guard_content? ":konacha, :driver => :#{driver}"
38
+ say "configuring Konacha js driver: #{driver}"
39
+ template_into 'Guard_konacha.erb', 'Guardfile'
40
+ end
41
+ end
42
+
43
+ protected
44
+
45
+ include EmberKonacha::GemHelper
46
+
47
+ def guard_file?
48
+ File.exist? guard_file
49
+ end
50
+
51
+ def guard_content? content
52
+ guard_file_content =~ /#{Regexp.escape content}/
53
+ end
54
+
55
+ def guard_file_content
56
+ @gfc ||= File.open(guard_file).read
57
+ end
58
+
59
+ def guard_file
60
+ Rails.root.join('Guardfile')
61
+ end
62
+
63
+ def validate_driver!
64
+ unless valid_driver? driver
65
+ say "Not a valid driver: #{driver}. Must be one of: #{valid_drivers}", :red
66
+ exit
67
+ end
68
+ end
69
+
70
+ def tpl_guard_koncha
71
+ @tpl ||= ERB.new template_content('Guard_konacha.erb')
72
+ end
73
+
74
+ def tpl_execute tpl
75
+ tpl.result(self.get_binding)
76
+ end
77
+
78
+ def get_binding
79
+ binding
80
+ end
81
+
82
+ def template_into tmp_source, target
83
+ gsub_file target, /guard :konacha/ do
84
+ driver_statement
85
+ end
86
+ end
87
+
88
+ def driver_statement
89
+ if self.respond_to?(driver, true)
90
+ send(driver)
91
+ else
92
+ say "No konacha config method found for: #{driver}, using default", :red
93
+ selenium
94
+ end
95
+ end
96
+
97
+ def driver
98
+ options[:driver] || 'selenium'
99
+ end
100
+
101
+ def valid_driver? name
102
+ valid_drivers.include? name.to_s
103
+ end
104
+
105
+ def valid_drivers
106
+ %w{selenium poltergeist webkit}
107
+ end
108
+
109
+ def selenium
110
+ %q{guard :konacha}
111
+ end
112
+
113
+ def poltergeist
114
+ %q{require 'capybara/poltergeist'
115
+ guard :konacha, :driver => :poltergeist}
116
+ end
117
+
118
+ def webkit
119
+ %q{require 'capybara-webkit'
120
+ guard :konacha, :driver => :webkit}
121
+ end
122
+
123
+ def template_content path
124
+ File.open(template_path path).read
125
+ end
126
+
127
+ def template_path path
128
+ File.join(TPL_PATH, path)
129
+ end
130
+
131
+ def init_guard!
132
+ say_status :run, "guard init"
133
+ %x[guard init]
134
+ end
135
+ end
136
+ end
137
+ end
138
+
@@ -1,3 +1,5 @@
1
+ require 'generators/ember_konacha/gem_helper'
2
+
1
3
  module EmberKonacha
2
4
  module Generators
3
5
  class InstallGenerator < Rails::Generators::Base
@@ -30,6 +32,8 @@ module EmberKonacha
30
32
  unless has_gem?('coffee-rails') || !coffee?
31
33
  gem 'coffee-rails'
32
34
  end
35
+
36
+ bundle_gems!
33
37
  end
34
38
 
35
39
  def create_infra_files
@@ -103,6 +107,8 @@ Using sinon-1.6.js supplied by this gem ;)}
103
107
 
104
108
  protected
105
109
 
110
+ include EmberKonacha::GemHelper
111
+
106
112
  def skip_driver
107
113
  @skipped_driver = true
108
114
  end
@@ -172,17 +178,6 @@ gem install therubyrhino
172
178
  end
173
179
  end
174
180
 
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
181
 
187
182
  def sinon_version
188
183
  @sinon_version ||= options[:sinon]
@@ -0,0 +1,4 @@
1
+ <%= driver_statement %>
2
+ watch(%r{^app/assets/javascripts/(.*)\.js(\.coffee)?$}) { |m| "#{m[1]}_spec.js" }
3
+ watch(%r{^spec/javascripts/.+_spec(\.js|\.js\.coffee)$})
4
+ end
@@ -27,6 +27,8 @@ window.TestUtil ||=
27
27
 
28
28
  # Useful for placing local test vars
29
29
  window.Test ||= {}
30
+ # Shorthand
31
+ window.T = Test
30
32
 
31
33
  # **** Global before / after ***
32
34
 
@@ -43,6 +45,9 @@ beforeEach( (done) ->
43
45
  # want to have complete control of runloops.
44
46
  Ember.testing = true
45
47
 
48
+ # reset all test variables!
49
+ window.Test = {}
50
+
46
51
  Ember.run( ->
47
52
  # Advance App readiness, which was deferred when the app
48
53
  # was created.
@@ -64,6 +69,9 @@ afterEach( ->
64
69
  App.reset()
65
70
  )
66
71
 
72
+ # reset all test variables!
73
+ window.Test = {}
74
+
67
75
  # Restore XHR
68
76
  window.server.restore()
69
77
  )
@@ -3,7 +3,17 @@
3
3
  describe "<%= helper_name %>", ->
4
4
  beforeEach( ->
5
5
  # setup
6
+ Test.helper = <%= helper_name %>
6
7
  )
7
8
 
8
9
  it "is there", ->
9
10
  assert.ok <%= helper_name %>
11
+
12
+ describe ".inc", ->
13
+ it "increments number", ->
14
+ Ember.run( ->
15
+ subject = 1
16
+ result = <%= helper_name %>.inc subject
17
+ )
18
+
19
+ expect(result).to.equal 2
@@ -9,9 +9,16 @@ describe "<%= model_name %>", ->
9
9
  assert.ok <%= model_name %>
10
10
  assert.ok DS.Model.detect(<%= model_name %>)
11
11
 
12
- describe "name", ->
13
- it "has a name", ->
12
+ describe "attribute: name", ->
13
+ it "can be created with valid value", ->
14
14
  Ember.run( ->
15
15
  Test.contact = <%= model_name %>.createRecord name: 'Joe'
16
16
  )
17
- assert.equal Test.contact.get('name'), 'Joe'
17
+ expect(Test.contact.get 'name').to.equal 'Joe'
18
+
19
+ it "can NOT be created with invalid value", ->
20
+ Ember.run( ->
21
+ Test.contact = <%= model_name %>.createRecord name: '123'
22
+ )
23
+ expect(Test.contact.get 'name').to.not.equal 'Joe'
24
+ expect(Test.contact.isValid).to.be false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ember-konacha-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kristian Mandrup
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-03 00:00:00.000000000 Z
11
+ date: 2013-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -83,10 +83,13 @@ files:
83
83
  - lib/ember/konacha/rails/version.rb
84
84
  - lib/generators/ember_konacha/base_helper.rb
85
85
  - lib/generators/ember_konacha/controller_spec_generator.rb
86
+ - lib/generators/ember_konacha/gem_helper.rb
87
+ - lib/generators/ember_konacha/guard_generator.rb
86
88
  - lib/generators/ember_konacha/helper_spec_generator.rb
87
89
  - lib/generators/ember_konacha/install_generator.rb
88
90
  - lib/generators/ember_konacha/model_spec_generator.rb
89
91
  - lib/generators/ember_konacha/templates/.DS_Store
92
+ - lib/generators/ember_konacha/templates/Guard_konacha.erb
90
93
  - lib/generators/ember_konacha/templates/konacha_config.js.coffee
91
94
  - lib/generators/ember_konacha/templates/sinon_mvc_mocks.js
92
95
  - lib/generators/ember_konacha/templates/spec_helper.js.coffee