Browse files

Use ammeter instead of aruba to test generators

* Tests are much faster
* Failures are improved
* Don't generate a Rails app inside each test
* Don't boot up Rails several times
  • Loading branch information...
1 parent 223dae6 commit 366ad3571b0fc81f681472eb0ae911f47c60a405 @jferris committed Apr 30, 2013
Showing with 42 additions and 62 deletions.
  1. +1 −0 effigy.gemspec
  2. +0 −62 features/rails_generators.feature
  3. +39 −0 spec/generators/effigy/view/view_generator_spec.rb
  4. +2 −0 spec/spec_helper.rb
View
1 effigy.gemspec
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'nokogiri', '>= 1.3'
+ s.add_development_dependency 'ammeter'
s.add_development_dependency 'aruba'
s.add_development_dependency 'cucumber'
s.add_development_dependency 'rails', '>= 3.2'
View
62 features/rails_generators.feature
@@ -1,62 +0,0 @@
-Feature: Generate views in a Rails application
-
- Background:
- When I generate a new rails app
- And I add "effigy" from this project as a dependency
- When I run `bundle install --local`
-
- @disable-bundler
- Scenario: generate a controller view and template
- When I run `bundle exec rails generate effigy:view users create`
- Then the file "app/views/users/create.html.effigy" should contain:
- """
- class UsersCreateView < Effigy::Rails::View
- private
- def transform
- # Apply transformations to the template file here:
- # text('h1', 'Hello')
- # Assigns from the action are available:
- # text('h1', @post.title)
- # Transformations will be applied to to the template file:
- # app/templates/users/create.html
- # See the documentation for more information.
- end
- end
- """
- Then the file "app/templates/users/create.html" should contain:
- """
- <h1>UsersCreateView</h1>
- <p>Edit me at app/templates/users/create.html</p>
- <p>Edit my view at app/views/users/create.html.effigy</p>
- """
-
- @disable-bundler
- Scenario: generate a layout view and template
- When I run `bundle exec rails generate effigy:view layouts narrow`
- Then the file "app/views/layouts/narrow.html.effigy" should contain:
- """
- class NarrowLayout < Effigy::Rails::View
- private
- def transform
- # Apply transformations to the template file here:
- # text('h1', 'Hello')
- # Assigns from the action are available:
- # text('h1', @post.title)
- # Transformations will be applied to to the template file:
- # app/templates/layouts/narrow.html
- # See the documentation for more information.
- html('body', content_for(:layout))
- end
- end
- """
- Then the file "app/templates/layouts/narrow.html" should contain:
- """
- <html>
- <body>
- <h1>NarrowLayout</h1>
- <p>Edit me at app/templates/layouts/narrow.html</p>
- <p>Edit my view at app/views/layouts/narrow.html.effigy</p>
- </body>
- </html>
- """
-
View
39 spec/generators/effigy/view/view_generator_spec.rb
@@ -0,0 +1,39 @@
+require 'spec_helper'
+require 'generators/effigy/view/view_generator'
+
+describe Effigy::Generators::ViewGenerator do
+ destination File.join(PROJECT_ROOT, 'tmp')
+ before { prepare_destination }
+
+ it 'generates an action view and template with the given name' do
+ run_generator %w(users create)
+
+ view = file('app/views/users/create.html.effigy')
+ view.should exist
+ view.should contain('class UsersCreateView < Effigy::Rails::View')
+ view.should contain('app/templates/users/create.html')
+
+ template = file('app/templates/users/create.html')
+ template.should exist
+ template.should contain('UsersCreateView')
+ template.should contain('Edit me at app/templates/users/create.html')
+ template.
+ should contain('Edit my view at app/views/users/create.html.effigy')
+ end
+
+ it 'generates a layout view and template' do
+ run_generator %w(layouts narrow)
+
+ view = file('app/views/layouts/narrow.html.effigy')
+ view.should exist
+ view.should contain('class NarrowLayout < Effigy::Rails::View')
+ view.should contain('app/templates/layouts/narrow.html')
+
+ template = file('app/templates/layouts/narrow.html')
+ template.should exist
+ template.should contain('NarrowLayout')
+ template.should contain('Edit me at app/templates/layouts/narrow.html')
+ template.
+ should contain('Edit my view at app/views/layouts/narrow.html.effigy')
+ end
+end
View
2 spec/spec_helper.rb
@@ -1,4 +1,6 @@
require 'rspec'
+require 'rails/all'
+require 'ammeter/init'
PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze
RAILS_ROOT = File.join(PROJECT_ROOT, 'tmp', 'rails_root')

0 comments on commit 366ad35

Please sign in to comment.