require './test/test_helper' class ResultsTest < GemStoneTest def setup reset_sandbox @valid_options = { :name => 'My gem', :author => 'Raul Murciano', :email => 'raul@murciano.net', :homepage => 'http://github.com/raul/my_gem', :description => 'A short description goes here', :summary => 'Lorem ipsum and so on', :executable => true, :gem_path => './test/sandbox' } GemStone::Generator.new @valid_options end ## Changelog.md def test_creates_changelog assert_file_created 'Changelog.md' end def test_changelog_includes_gem_name_in_title assert_file_includes 'Changelog.md', '# My gem changelog' end def test_changelog_includes_v_0_1 assert_file_includes 'Changelog.md', '## v0.1' end ## Gemfile def test_creates_gemfile assert_file_created 'Gemfile' end def test_gemfile_remains_identical assert_file_equals_template 'Gemfile' end # my_gem.gemspec def test_creates_gemspec assert_file_created 'my_gem.gemspec' end def test_gemspec_requires_lib assert_file_includes 'my_gem.gemspec', 'require File.expand_path("./lib/my_gem")' end def test_gemspec_includes_name assert_file_includes 'my_gem.gemspec', 's.name = "My gem"' end def test_gemspec_includes_authors assert_file_includes 'my_gem.gemspec', 's.authors = ["Raul Murciano"]' end def test_gemspec_includes_email assert_file_includes 'my_gem.gemspec', 's.email = ["raul@murciano.net"]' end def test_gemspec_includes_version assert_file_includes 'my_gem.gemspec', 's.version = MyGem::VERSION' end def test_gemspec_includes_platform assert_file_includes 'my_gem.gemspec', 's.platform = Gem::Platform::RUBY' end def test_gemspec_includes_rubyforge_project assert_file_includes 'my_gem.gemspec', 's.rubyforge_project = "my_gem"' end def test_gemspec_includes_summary assert_file_includes 'my_gem.gemspec', 's.summary = "Lorem ipsum and so on"' end def test_gemspec_includes_homepage assert_file_includes 'my_gem.gemspec', 's.homepage = "http://github.com/raul/my_gem"' end def test_gemspec_includes_description assert_file_includes 'my_gem.gemspec', 's.description = "A short description goes here"' end ## README.md def test_creates_readme assert_file_created 'README.md' end def test_readme_includes_gem_name_as_title assert_file_includes 'README.md', '# My gem' end def test_readme_includes_dummy_doc assert_file_includes 'README.md', 'This documentation needs more love from Raul Murciano' end def test_readme_includes_copyright assert_file_includes 'README.md', "Copyright (C) #{Time.now.year} Raul Murciano " end def test_readme_mentions_license assert_file_includes 'README.md', 'See the LICENSE file included in the distribution.' end ## lib/my_gem.rb def test_creates_lib_file assert_file_created 'lib/my_gem.rb' end def test_lib_file_includes_class assert_file_includes 'lib/my_gem.rb', 'class MyGem' end def test_lib_file_includes_version assert_file_includes 'lib/my_gem.rb', "VERSION = '0.1'" end ## LICENSE def test_creates_license assert_file_created 'LICENSE' end def test_license_includes_author assert_file_includes 'LICENSE', 'Raul Murciano' end def test_license_includes_email assert_file_includes 'LICENSE', 'raul@murciano.net' end ## Rakefile def test_creates_rakefile assert_file_created 'Rakefile' end def test_rakefile_remains_identical assert_file_equals_template 'Rakefile' end ## test/test_helper.rb def test_creates_test_helper assert_file_created 'test/test_helper.rb' end def test_test_helper_requires_rubygems assert_file_includes 'test/test_helper.rb', "require 'rubygems'" end def test_test_helper_requires_minitest assert_file_includes 'test/test_helper.rb', "require 'minitest/autorun'" end def test_test_helper_requires_gem_lib assert_file_includes 'test/test_helper.rb', "require './lib/my_gem'" end ## test/my_gem_test.rb def test_creates_test_file assert_file_created 'test/my_gem_test.rb' end def test_test_file_requires_test_helper assert_file_includes 'test/my_gem_test.rb', "require './test/test_helper'" end def test_test_file_includes_test_class assert_file_includes 'test/my_gem_test.rb', 'class MyGemTest < MiniTest::Unit::TestCase' end ## bin/my_gem def test_doesnt_create_executable_if_not_selected @valid_options[:executable] = false reset_sandbox GemStone::Generator.new @valid_options assert_file_not_created 'bin/my_gem' end def test_creates_executable_if_selected assert_file_created 'bin/my_gem' end def test_executable_includes_ruby_shebang assert_file_includes 'bin/my_gem', "#!/usr/bin/env ruby" end def test_executable_includes_dummy_code assert_file_includes 'bin/my_gem', 'puts "This executable needs more love from Raul Murciano"' end def test_executable_is_executable assert_executable_file 'bin/my_gem' end protected ## test helpers def assert_file_includes(file_path, content) path = sandboxed_path file_path assert File.file?(path) && File.read(path).include?(content), "String '#{content}' not found in #{path}" end def assert_file_created(file_path) path = sandboxed_path file_path assert File.file?(path), "#{path} file not found" end def assert_file_not_created(file_path) path = sandboxed_path file_path assert !File.file?(path), "#{path} file found, and should not exist" end def assert_file_equals_template(file_path) templates_path = './template' template_path = File.join templates_path, file_path assert FileUtils.compare_file(template_path, sandboxed_path(file_path)) end def assert_executable_file(file_path) path = sandboxed_path file_path assert `ls -la #{path}`.include?('-rwxr-xr-x'), "#{file_path} is not executable" end end