test/rails/widget_generator_test.rb in apotomo-0.1.4 vs test/rails/widget_generator_test.rb in apotomo-1.0.0.beta1

- old
+ new

@@ -1,47 +1,50 @@ require 'test_helper' -require 'rails_generator' -require 'rails_generator/scripts/generate' +require 'generators/apotomo/widget_generator' -Rails::Generator::Base.append_sources Rails::Generator::PathSource.new(:apotomo, File.join(File.dirname(__FILE__)+'/../../generators')) - -class WidgetGeneratorTest < Test::Unit::TestCase - context "Running script/generate widget" do - setup do - FileUtils.mkdir_p(fake_rails_root) - @original_files = file_list - end - - teardown do - FileUtils.rm_r(fake_rails_root) - end - - context "MouseWidget squeak snuggle" do +class WidgetGeneratorTest < Rails::Generators::TestCase + destination File.join(Rails.root, "tmp") + setup :prepare_destination + tests ::Apotomo::Generators::WidgetGenerator + + context "Running rails g apotomo::widget" do + context "Mouse squeak snuggle" do should "create the standard assets" do - Rails::Generator::Scripts::Generate.new.run(%w(widget MouseWidget squeak snuggle), :destination => fake_rails_root) - files = (file_list - @original_files) - assert files.include?(fake_rails_root+"/app/cells/mouse_widget.rb") - assert files.include?(fake_rails_root+"/app/cells/mouse_widget/squeak.html.erb") - assert files.include?(fake_rails_root+"/app/cells/mouse_widget/snuggle.html.erb") - assert files.include?(fake_rails_root+"/test/widgets/mouse_widget_test.rb") + + run_generator %w(MouseWidget squeak snuggle) + + assert_file "app/cells/mouse_widget.rb", /class MouseWidget < Apotomo::Widget/ + assert_file "app/cells/mouse_widget.rb", /def snuggle/ + assert_file "app/cells/mouse_widget.rb", /def squeak/ + assert_file "app/cells/mouse_widget/snuggle.html.erb", %r(app/cells/mouse_widget/snuggle\.html\.erb) + assert_file "app/cells/mouse_widget/snuggle.html.erb", %r(<p>) + assert_file "app/cells/mouse_widget/squeak.html.erb", %r(app/cells/mouse_widget/squeak\.html\.erb) + + assert_file "test/widgets/mouse_widget_test.rb", %r(class MouseWidgetTest < Apotomo::TestCase) end should "create haml assets with --haml" do - Rails::Generator::Scripts::Generate.new.run(%w(widget MouseWidget squeak snuggle --haml), :destination => fake_rails_root) - files = (file_list - @original_files) - assert files.include?(fake_rails_root+"/app/cells/mouse_widget.rb") - assert files.include?(fake_rails_root+"/app/cells/mouse_widget/squeak.html.haml") - assert files.include?(fake_rails_root+"/app/cells/mouse_widget/snuggle.html.haml") - assert files.include?(fake_rails_root+"/test/widgets/mouse_widget_test.rb") + run_generator %w(MouseWidget squeak snuggle --haml) + + assert_file "app/cells/mouse_widget.rb", /class MouseWidget < Apotomo::Widget/ + assert_file "app/cells/mouse_widget.rb", /def snuggle/ + assert_file "app/cells/mouse_widget.rb", /def squeak/ + assert_file "app/cells/mouse_widget/snuggle.html.haml", %r(app/cells/mouse_widget/snuggle\.html\.haml) + assert_file "app/cells/mouse_widget/snuggle.html.haml", %r(%p) + assert_file "app/cells/mouse_widget/squeak.html.haml", %r(app/cells/mouse_widget/squeak\.html\.haml) + assert_file "test/widgets/mouse_widget_test.rb" end + + should "create haml assets with -t haml" do + run_generator %w(MouseWidget snuggle squeak -t haml) + + assert_file "app/cells/mouse_widget.rb", /class MouseWidget < Apotomo::Widget/ + assert_file "app/cells/mouse_widget.rb", /def snuggle/ + assert_file "app/cells/mouse_widget.rb", /def squeak/ + assert_file "app/cells/mouse_widget/snuggle.html.haml", %r(app/cells/mouse_widget/snuggle\.html\.haml) + assert_file "app/cells/mouse_widget/snuggle.html.haml", %r(%p) + assert_file "app/cells/mouse_widget/squeak.html.haml", %r(app/cells/mouse_widget/squeak\.html\.haml) + assert_file "test/widgets/mouse_widget_test.rb" + end end end - - private - def fake_rails_root - File.join(File.dirname(__FILE__), 'rails_root') - end - - def file_list - Dir.glob(File.join(fake_rails_root, "**/*")) - end end