Permalink
Browse files

Add scenario for contexts

  • Loading branch information...
1 parent d85bc08 commit c4a64cab80ca56c265127fd4cea604e1e5dcd7e1 @stevehodgkiss committed Mar 7, 2011
@@ -4,7 +4,7 @@
include GeneratorSpec::TestCase
tests TestGenerator
destination File.expand_path("../../tmp", __FILE__)
- arguments %w(test)
+ arguments %w(test --test)
before do
prepare_destination
@@ -27,7 +27,7 @@ class TestClass
include GeneratorSpec::TestCase
tests TestGenerator
destination File.expand_path("../../tmp", __FILE__)
- arguments %w(test)
+ arguments %w(test --test)
before(:all) do
prepare_destination
@@ -45,4 +45,27 @@ class TestClass
it "removes files" do
assert_no_file ".gitignore"
end
+end
+
+describe TestGenerator, "with contexts" do
+ include GeneratorSpec::TestCase
+ tests TestGenerator
+ destination File.expand_path("../../tmp", __FILE__)
+ before { prepare_destination }
+
+ context "with --test flag" do
+ before { run_generator %w(test --test) }
+
+ it "creates a test initializer" do
+ assert_file "config/initializers/test.rb", "# Initializer"
+ end
+ end
+
+ context "without any flags" do
+ before { run_generator %w(test) }
+
+ it "doesn't create a test initializer" do
+ assert_no_file "config/initializers/test.rb"
+ end
+ end
end
@@ -1,9 +1,10 @@
class TestGenerator < Rails::Generators::Base
argument :name, :type => :string
+ class_option :test, :type => :boolean, :default => false
source_root File.expand_path('../templates', __FILE__)
def copy_initializer
- template "initializer.rb", "config/initializers/test.rb"
+ template "initializer.rb", "config/initializers/test.rb" if options[:test]
end
def create_migration

0 comments on commit c4a64ca

Please sign in to comment.