Sha256: 6b1f2faca3f8fdacad44ca7d33779f30ce6234f02214d565047ac23ecb74e243

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

require "minitest/autorun"
require "minitest-rails"

require "rails"
require "rails/generators"

require "generators/mini_test/scaffold/scaffold_generator"

require "fileutils"

class TestScaffoldGenerator < MiniTest::Unit::TestCase
  Rails::Generators.no_color!

  def test_scaffold_generator
    text = capture(:stdout) do
      MiniTest::Generators::ScaffoldGenerator.start ["user"]
    end
    assert_match(/create  test\/controllers\/user_controller_test.rb/m, text)
    assert File.exists? "test/controllers/user_controller_test.rb"
    contents = open("test/controllers/user_controller_test.rb").read
    assert_match(/class UserControllerTest < MiniTest::Rails::Controller/m, contents)
    assert_match(/def test_index/m, contents)
  ensure
    # TODO: Don"t write the files
    # I agree, it would be better to mock the file getting written
    FileUtils.rm_r "test/controllers"
  end

  def test_scaffold_generator_spec
    text = capture(:stdout) do
      MiniTest::Generators::ScaffoldGenerator.start ["user", "--spec"]
    end
    assert_match(/create  test\/controllers\/user_controller_test.rb/m, text)
    assert File.exists? "test/controllers/user_controller_test.rb"
    contents = open("test/controllers/user_controller_test.rb").read
    assert_match(/class UserControllerTest < MiniTest::Rails::Controller/m, contents)
    assert_match(/it "must get index"/m, contents)
  ensure
    FileUtils.rm_r "test/controllers"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
minitest-rails-0.0.5 test/test_scaffold_generator.rb
minitest-rails-0.0.4 test/test_scaffold_generator.rb