Permalink
Browse files

Add FakeFS

Trying to get Travis-CI to be happy.
  • Loading branch information...
blowmage committed Jul 29, 2012
1 parent fa25ede commit 5106aa26f23eac5a364308458120d7183f5db98e
View
@@ -19,8 +19,9 @@ Hoe.spec 'minitest-rails' do
self.readme_file = "README.rdoc"
self.testlib = :minitest
- extra_deps << ['minitest', '~> 3.0']
- extra_deps << ['rails', '~> 3.0']
+ dependency 'minitest', '~> 3.0'
+ dependency 'rails', '~> 3.0'
+ dependency 'fakefs', '~> 0.4', :dev
end
# vim: syntax=ruby
@@ -6,59 +6,66 @@
require "generators/mini_test/controller/controller_generator"
-require "fileutils"
+require "fakefs/safe"
+
+class FakeFS::File
+ def self.binread file
+ File.open(file, "rb") { |f| f.read }
+ end
+end
class TestControllerGenerator < MiniTest::Unit::TestCase
- Rails::Generators.no_color!
+ def setup
+ Rails::Generators.no_color!
+ FakeFS.activate!
+ FakeFS::FileSystem.clone "lib/generators"
+ end
+
+ def teardown
+ FakeFS::FileSystem.clear
+ FakeFS.deactivate!
+ end
def test_controller_generator
text = capture(:stdout) do
MiniTest::Generators::ControllerGenerator.start ["user"]
end
- assert_match(/create test\/controllers\/user_controller_test.rb/m, text)
+ 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/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"
+ contents = File.read "test/controllers/user_controller_test.rb"
+ assert_match /class UserControllerTest/m, contents
end
def test_namespaced_controller_generator
text = capture(:stdout) do
MiniTest::Generators::ControllerGenerator.start ["admin/user"]
end
- assert_match(/create test\/controllers\/admin\/user_controller_test.rb/m, text)
+ assert_match /create test\/controllers\/admin\/user_controller_test.rb/m, text
assert File.exists? "test/controllers/admin/user_controller_test.rb"
- contents = open("test/controllers/admin/user_controller_test.rb").read
- assert_match(/class Admin::UserControllerTest/m, contents)
- ensure
- FileUtils.rm_r "test/controllers"
+ contents = File.read "test/controllers/admin/user_controller_test.rb"
+ assert_match /class Admin::UserControllerTest/m, contents
end
def test_controller_generator_spec
text = capture(:stdout) do
MiniTest::Generators::ControllerGenerator.start ["user", "--spec"]
end
- assert_match(/create test\/controllers\/user_controller_test.rb/m, text)
+ 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(/describe UserController do/m, contents)
- ensure
- FileUtils.rm_r "test/controllers"
+ contents = File.read "test/controllers/user_controller_test.rb"
+ assert_match /describe UserController do/m, contents
end
def test_namespaced_controller_generator_spec
- text = capture(:stdout) do
- MiniTest::Generators::ControllerGenerator.start ["admin/user", "--spec"]
+ FakeFS do
+ text = capture(:stdout) do
+ MiniTest::Generators::ControllerGenerator.start ["admin/user", "--spec"]
+ end
+ assert_match /create test\/controllers\/admin\/user_controller_test.rb/m, text
+ assert File.exists? "test/controllers/admin/user_controller_test.rb"
+ contents = File.read "test/controllers/admin/user_controller_test.rb"
+ assert_match /describe Admin::UserController do/m, contents
end
- assert_match(/create test\/controllers\/admin\/user_controller_test.rb/m, text)
- assert File.exists? "test/controllers/admin/user_controller_test.rb"
- contents = open("test/controllers/admin/user_controller_test.rb").read
- assert_match(/describe Admin::UserController do/m, contents)
- ensure
- FileUtils.rm_r "test/controllers"
end
end
@@ -6,59 +6,64 @@
require "generators/mini_test/helper/helper_generator"
-require "fileutils"
+require "fakefs/safe"
+
+class FakeFS::File
+ def self.binread file
+ File.open(file, "rb") { |f| f.read }
+ end
+end
class TestHelperGenerator < MiniTest::Unit::TestCase
- Rails::Generators.no_color!
+ def setup
+ Rails::Generators.no_color!
+ FakeFS.activate!
+ FakeFS::FileSystem.clone "lib/generators"
+ end
+
+ def teardown
+ FakeFS::FileSystem.clear
+ FakeFS.deactivate!
+ end
def test_helper_generator
- text = capture(:stdout) do
+ text = capture :stdout do
MiniTest::Generators::HelperGenerator.start ["user"]
end
- assert_match(/create test\/helpers\/user_helper_test.rb/m, text)
+ assert_match /create test\/helpers\/user_helper_test.rb/m, text
assert File.exists? "test/helpers/user_helper_test.rb"
- contents = open("test/helpers/user_helper_test.rb").read
- assert_match(/class UserHelperTest < MiniTest::Rails::ActionView::TestCase/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/helpers"
+ contents = File.read "test/helpers/user_helper_test.rb"
+ assert_match /class UserHelperTest < MiniTest::Rails::ActionView::TestCase/m, contents
end
def test_namespaced_helper_generator
- text = capture(:stdout) do
+ text = capture :stdout do
MiniTest::Generators::HelperGenerator.start ["admin/user"]
end
- assert_match(/create test\/helpers\/admin\/user_helper_test.rb/m, text)
+ assert_match /create test\/helpers\/admin\/user_helper_test.rb/m, text
assert File.exists? "test/helpers/admin/user_helper_test.rb"
- contents = open("test/helpers/admin/user_helper_test.rb").read
- assert_match(/class Admin::UserHelperTest < MiniTest::Rails::ActionView::TestCase/m, contents)
- ensure
- FileUtils.rm_r "test/helpers"
+ contents = File.read "test/helpers/admin/user_helper_test.rb"
+ assert_match /class Admin::UserHelperTest < MiniTest::Rails::ActionView::TestCase/m, contents
end
def test_helper_generator_spec
- text = capture(:stdout) do
+ text = capture :stdout do
MiniTest::Generators::HelperGenerator.start ["user", "--spec"]
end
- assert_match(/create test\/helpers\/user_helper_test.rb/m, text)
+ assert_match /create test\/helpers\/user_helper_test.rb/m, text
assert File.exists? "test/helpers/user_helper_test.rb"
- contents = open("test/helpers/user_helper_test.rb").read
- assert_match(/describe UserHelper do/m, contents)
- ensure
- FileUtils.rm_r "test/helpers"
+ contents = File.read "test/helpers/user_helper_test.rb"
+ assert_match /describe UserHelper do/m, contents
end
def test_namespaced_helper_generator_spec
- text = capture(:stdout) do
+ text = capture :stdout do
MiniTest::Generators::HelperGenerator.start ["admin/user", "--spec"]
end
- assert_match(/create test\/helpers\/admin\/user_helper_test.rb/m, text)
+ assert_match /create test\/helpers\/admin\/user_helper_test.rb/m, text
assert File.exists? "test/helpers/admin/user_helper_test.rb"
- contents = open("test/helpers/admin/user_helper_test.rb").read
- assert_match(/describe Admin::UserHelper do/m, contents)
- ensure
- FileUtils.rm_r "test/helpers"
+ contents = File.read "test/helpers/admin/user_helper_test.rb"
+ assert_match /describe Admin::UserHelper do/m, contents
end
end
@@ -6,23 +6,34 @@
require "generators/mini_test/install/install_generator"
-require "fileutils"
+require "fakefs/safe"
+
+class FakeFS::File
+ def self.binread file
+ File.open(file, "rb") { |f| f.read }
+ end
+end
class TestInstallGenerator < MiniTest::Unit::TestCase
- Rails::Generators.no_color!
+ def setup
+ Rails::Generators.no_color!
+ FakeFS.activate!
+ FakeFS::FileSystem.clone "lib/generators"
+ end
+
+ def teardown
+ FakeFS::FileSystem.clear
+ FakeFS.deactivate!
+ end
def test_install_generator
- text = capture(:stdout) do
+ text = capture :stdout do
MiniTest::Generators::InstallGenerator.start
end
- assert_match(/create test\/minitest_helper.rb/m, text)
+ assert_match /create test\/minitest_helper.rb/m, text
assert File.exists? "test/minitest_helper.rb"
- contents = open("test/minitest_helper.rb").read
- assert_match(/require "minitest\/autorun"/m, contents)
- assert_match(/require "minitest\/rails"/m, contents)
- ensure
- # TODO: Don"t write the files
- # I agree, it would be better to mock the file getting written
- FileUtils.rm "test/minitest_helper.rb"
+ contents = File.read "test/minitest_helper.rb"
+ assert_match /require "minitest\/autorun"/m, contents
+ assert_match /require "minitest\/rails"/m, contents
end
end
@@ -6,33 +6,48 @@
require "generators/mini_test/mailer/mailer_generator"
-require "fileutils"
+require "fakefs/safe"
+
+class FakeFS::File
+ def self.binread file
+ File.open(file, "rb") { |f| f.read }
+ end
+end
class TestMailerGenerator < MiniTest::Unit::TestCase
- Rails::Generators.no_color!
+ def setup
+ Rails::Generators.no_color!
+ FakeFS.activate!
+ FakeFS::FileSystem.clone "lib/generators"
+ end
+
+ def teardown
+ FakeFS::FileSystem.clear
+ FakeFS.deactivate!
+ end
def test_mailer_generator
- text = capture(:stdout) do
+ text = capture :stdout do
MiniTest::Generators::MailerGenerator.start ["notification"]
end
- assert_match(/create test\/mailers\/notification_test.rb/m, text)
+ assert_match /create test\/mailers\/notification_test.rb/m, text
assert File.exists? "test/mailers/notification_test.rb"
- contents = open("test/mailers/notification_test.rb").read
- assert_match(/class NotificationTest/m, contents)
+ contents = File.read "test/mailers/notification_test.rb"
+ assert_match /class NotificationTest/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/mailers"
end
def test_mailer_generator_spec
- text = capture(:stdout) do
+ text = capture :stdout do
MiniTest::Generators::MailerGenerator.start ["notification", "welcome", "--spec"]
end
- assert_match(/create test\/mailers\/notification_test.rb/m, text)
+ assert_match /create test\/mailers\/notification_test.rb/m, text
assert File.exists? "test/mailers/notification_test.rb"
- contents = open("test/mailers/notification_test.rb").read
- assert_match(/describe Notification do/m, contents)
+ contents = File.read "test/mailers/notification_test.rb"
+ assert_match /describe Notification do/m, contents
ensure
FileUtils.rm_r "test/mailers"
end
@@ -6,19 +6,34 @@
require "generators/mini_test/model/model_generator"
-require "fileutils"
+require "fakefs/safe"
+
+class FakeFS::File
+ def self.binread file
+ File.open(file, "rb") { |f| f.read }
+ end
+end
class TestModelGenerator < MiniTest::Unit::TestCase
- Rails::Generators.no_color!
+ def setup
+ Rails::Generators.no_color!
+ FakeFS.activate!
+ FakeFS::FileSystem.clone "lib/generators"
+ end
+
+ def teardown
+ FakeFS::FileSystem.clear
+ FakeFS.deactivate!
+ end
def test_model_generator
- text = capture(:stdout) do
+ text = capture :stdout do
MiniTest::Generators::ModelGenerator.start ["user"]
end
- assert_match(/create test\/models\/user_test.rb/m, text)
+ assert_match /create test\/models\/user_test.rb/m, text
assert File.exists? "test/models/user_test.rb"
- contents = open("test/models/user_test.rb").read
- assert_match(/class UserTest/m, contents)
+ contents = File.read "test/models/user_test.rb"
+ assert_match /class UserTest/m, contents
ensure
# TODO: Don"t write the files
# I agree, it would be better to mock the file getting written
@@ -27,35 +42,35 @@ def test_model_generator
end
def test_model_generator_spec
- text = capture(:stdout) do
+ text = capture :stdout do
MiniTest::Generators::ModelGenerator.start ["user", "--spec"]
end
- assert_match(/create test\/models\/user_test.rb/m, text)
+ assert_match /create test\/models\/user_test.rb/m, text
assert File.exists? "test/models/user_test.rb"
assert File.exists? "test/fixtures/users.yml"
- contents = open("test/models/user_test.rb").read
- assert_match(/describe User do/m, contents)
+ contents = File.read "test/models/user_test.rb"
+ assert_match /describe User do/m, contents
ensure
FileUtils.rm_r "test/models"
FileUtils.rm_r "test/fixtures"
end
def test_model_generator_fixture
- text = capture(:stdout) do
+ text = capture :stdout do
MiniTest::Generators::ModelGenerator.start ["user"]
end
- assert_match(/create test\/fixtures\/users.yml/m, text)
+ assert_match /create test\/fixtures\/users.yml/m, text
assert File.exists? "test/fixtures/users.yml"
ensure
FileUtils.rm_r "test/models"
FileUtils.rm_r "test/fixtures"
end
def test_model_generator_skip_fixture
- text = capture(:stdout) do
+ text = capture :stdout do
MiniTest::Generators::ModelGenerator.start ["user", "--skip-fixture"]
end
- refute_match(/create test\/fixtures\/users.yml/m, text)
+ refute_match /create test\/fixtures\/users.yml/m, text
refute File.exists? "test/fixtures/users.yml"
ensure
FileUtils.rm_r "test/models"
Oops, something went wrong.

0 comments on commit 5106aa2

Please sign in to comment.