Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

default to generate files in tmpdir/ammeter instead of forcing you to…

… specify in spec (you can still override with "destination")
  • Loading branch information...
commit 17f2e03a46d5bac7d2391bfdc4fe97ff663875ab 1 parent 684761b
@alexrothenberg authored
View
44 features/generator_spec.feature
@@ -35,8 +35,6 @@ Feature: generator spec
require 'generators/awesome/awesome_generator'
describe AwesomeGenerator do
- destination File.expand_path("../../tmp", __FILE__)
-
before { run_generator %w(my_dir) }
describe 'public/my_dir/awesome.html' do
subject { file('public/my_dir/awesome.html') }
@@ -62,7 +60,6 @@ Feature: generator spec
require 'generators/awesome/awesome_generator'
describe AwesomeGenerator do
- destination File.expand_path("../../tmp", __FILE__)
arguments %w(another_dir)
before { invoke_task :create_awesomeness }
@@ -81,15 +78,13 @@ Feature: generator spec
When I run `rake spec`
Then the output should contain "4 examples, 0 failures"
- Scenario: A spec with some failures shows good error messages
+ Scenario: A spec with some failures shows nice error messages
Given a file named "spec/generators/awesome_generator_spec.rb" with:
"""
require "spec_helper"
require 'generators/awesome/awesome_generator'
describe AwesomeGenerator do
- destination File.expand_path("../../tmp", __FILE__)
-
before { run_generator %w(my_dir) }
describe 'public/my_dir/awesome.html' do
subject { file('public/my_dir/awesome.html') }
@@ -111,19 +106,19 @@ Feature: generator spec
Then the output should contain "5 examples, 5 failures"
And the output should contain:
"""
- /tmp/public/my_dir/awesome.html to not contain "This is an awesome file" but it did
+ /public/my_dir/awesome.html to not contain "This is an awesome file" but it did
"""
And the output should contain:
"""
- /tmp/public/my_dir/awesome.html to contain "This text is not in the file" but it contained "This is an awesome file"
+ /public/my_dir/awesome.html to contain "This text is not in the file" but it contained "This is an awesome file"
"""
And the output should contain:
"""
- /tmp/public/my_dir/awesome.html" not to exist
+ /public/my_dir/awesome.html" not to exist
"""
And the output should contain:
"""
- /tmp/public/my_dir/non_existent.html" to exist
+ /public/my_dir/non_existent.html" to exist
"""
And the output should contain:
"""
@@ -137,7 +132,6 @@ Feature: generator spec
require 'generators/awesome/awesome_generator'
describe AwesomeGenerator do
- destination File.expand_path("../../tmp", __FILE__)
arguments %w(my_dir --super)
before { generator.invoke_all }
@@ -161,12 +155,7 @@ Feature: generator spec
require 'rails/generators/active_record/migration/migration_generator'
describe ActiveRecord::Generators::MigrationGenerator do
- destination File.expand_path("../../tmp", __FILE__)
-
- before do
- prepare_destination
- run_generator %w(create_posts)
- end
+ before { run_generator %w(create_posts) }
subject { migration_file('db/migrate/create_posts.rb') }
it { should exist }
it { should contain 'class CreatePosts < ActiveRecord::Migration' }
@@ -175,4 +164,25 @@ Feature: generator spec
When I run `rake spec`
Then the output should contain "2 examples, 0 failures"
+ Scenario: Can tell the generator where to put its files
+ Given a file named "spec/generators/awesome_generator_spec.rb" with:
+ """
+ require "spec_helper"
+ require 'generators/awesome/awesome_generator'
+
+ describe AwesomeGenerator do
+ destination Rails.root + 'tmp/generated_files'
+
+ before { run_generator %w(my_dir --super) }
+ describe 'public/my_dir/super_awesome.html' do
+ subject { file('public/my_dir/super_awesome.html') }
+ it { should == "#{Rails.root}/tmp/generated_files/public/my_dir/super_awesome.html" }
+ it { should exist }
+ end
+ end
+ """
+ When I run `rake spec`
+ Then the output should contain "2 examples, 0 failures"
+
+
View
16 lib/ammeter/rspec/generator/example/generator_example_group.rb
@@ -2,6 +2,8 @@
require 'active_support/core_ext'
require 'rspec/rails/adapters'
require 'rspec/rails/example/rails_example_group'
+require 'tmpdir'
+require 'fileutils'
module Ammeter
module RSpec
@@ -19,7 +21,7 @@ module ClassMethods
DELEGATED_METHODS.each do |method|
delegate method, :to => :'self.test_unit_test_case_delegate'
end
- delegate :destination, :arguments, :to => :'self.test_unit_test_case_delegate.class'
+ delegate :destination, :arguments, :to => ::Rails::Generators::TestCase
def initialize_delegate
self.test_unit_test_case_delegate = ::Rails::Generators::TestCase.new 'pending'
@@ -50,23 +52,17 @@ def invoke_task name
DELEGATED_METHODS.each do |method|
delegate method, :to => :'self.class'
end
- def destination_root_is_set? #:nodoc:
- raise "You need to configure your Rails::Generators::TestCase destination root." unless destination_root
- end
- def ensure_current_path #:nodoc:
- # cd current_path
- end
+ ::Rails::Generators::TestCase.destination File.expand_path('ammeter', Dir.tmpdir)
initialize_delegate
subject { generator }
before do
self.class.initialize_delegate
- destination_root_is_set?
- ensure_current_path
+ prepare_destination
end
after do
- ensure_current_path
+ # ensure_current_path
end
metadata[:type] = :generator
end
View
6 spec/ammeter/rspec/rails/generator/example/generator_example_group_spec.rb
@@ -30,15 +30,9 @@ module Ammeter::RSpec::Rails
end
describe 'able to delegate to ::Rails::Generators::TestCase' do
- it 'should know the destination is not set' do
- lambda { group.destination_root_is_set? }.should raise_error "You need to configure your Rails::Generators::TestCase destination root."
- end
describe 'with a destination root' do
before { group.destination '/some/path' }
its(:destination_root) { should == '/some/path' }
- it 'should know the destination is set' do
- lambda { group.destination_root_is_set? }.should_not raise_error
- end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.