test/jeweler/test_specification.rb in jeweler-1.3.0 vs test/jeweler/test_specification.rb in jeweler-1.4.0

- old
+ new

@@ -1,61 +1,231 @@ require 'test_helper' class TestSpecification < Test::Unit::TestCase def setup - remove_tmpdir! - path = File.join(FIXTURE_DIR, "existing-project-with-version-yaml") - Git.init(path) - FileUtils.cp_r path, tmp_dir - #breakpoint + @project = create_construct + end + def teardown + @project.destroy! + end - @spec = Gem::Specification.new - @spec.extend(Jeweler::Specification) - @spec.set_jeweler_defaults(tmp_dir) + def build_jeweler_gemspec(&block) + gemspec = if block + Gem::Specification.new(&block) + else + Gem::Specification.new() + end + gemspec.extend(Jeweler::Specification) + gemspec end - def teardown - remove_tmpdir! + context "basic defaults" do + setup do + @gemspec = build_jeweler_gemspec + end + + should "make files a FileList" do + assert_equal FileList, @gemspec.files.class + end + + should "make test_files a FileList" do + assert_equal FileList, @gemspec.test_files.class + end + + should "make extra_rdoc_files a FileList" do + assert_equal FileList, @gemspec.extra_rdoc_files.class + end + + should "enable rdoc" do + assert @gemspec.has_rdoc + end end + + context "there aren't any executables in the project directory" do + setup do + @project.directory 'bin' + end - context "Gem::Specification with Jeweler monkey-patches" do - context "when setting defaults" do - should_eventually "should populate `files'" do - # this implementation changed to use ruby-git - assert_equal %w{Rakefile VERSION.yml bin/foo_the_ultimate_bin lib/foo_the_ultimate_lib.rb }, @spec.files.sort + context "and there hasn't been any set on the gemspec" do + setup do + @gemspec = build_jeweler_gemspec + @gemspec.set_jeweler_defaults(@project) end - should "should populate `executables'" do - assert_equal %w{ foo_the_ultimate_bin }, @spec.executables + + should "have empty gemspec executables" do + assert_equal [], @gemspec.executables end + end - context "with values already set" do - setup do - @spec.files = %w{ hey_include_me_in_gemspec } - @spec.set_jeweler_defaults(fixture_dir) + context "and has been previously set executables" do + setup do + @gemspec = build_jeweler_gemspec do |gemspec| + gemspec.executables = %w(non-existant) end + @gemspec.set_jeweler_defaults(@project) + end - should "not re-populate `files'" do - assert_equal %w{ hey_include_me_in_gemspec }, @spec.files + should "have only the original executables in the gemspec" do + assert_equal %w(non-existant), @gemspec.executables + end + end + end + + context "there are multiple executables in the project directory" do + setup do + @project.directory('bin') do |bin| + bin.file 'burnination' + bin.file 'trogdor' + end + end + + context "and there hasn't been any set on the gemspec" do + setup do + @gemspec = build_jeweler_gemspec + @gemspec.set_jeweler_defaults(@project) + end + + should "have the executables in the gemspec" do + assert_equal %w(burnination trogdor), @gemspec.executables + end + end + context "and has been previously set executables" do + setup do + @gemspec = build_jeweler_gemspec do |gemspec| + gemspec.executables = %w(burnination) end + @gemspec.set_jeweler_defaults(@project) end + should "have only the original executables in the gemspec" do + assert_equal %w(burnination), @gemspec.executables + end + end + end - context "for rdoc" do - should "be enabled" do - assert @spec.has_rdoc + context "there are mutiple extconf.rb in the project directory" do + setup do + @project.directory('ext') do |ext| + ext.file 'extconf.rb' + ext.directory('trogdor_native') do |trogdor_native| + trogdor_native.file 'extconf.rb' end + end + end - should "be utf-8" do - assert @spec.rdoc_options.include?('--charset=UTF-8') + context "and there hasn't been any extensions set on the gemspec" do + setup do + @gemspec = build_jeweler_gemspec + @gemspec.set_jeweler_defaults(@project) + end + + should "have all the extconf.rb files in extensions" do + assert_equal %w(ext/extconf.rb ext/trogdor_native/extconf.rb), @gemspec.extensions + end + + end + + end + + context "there are some files and is setup for git" do + setup do + @project.file 'Rakefile' + @project.directory('lib') do |lib| + lib.file 'example.rb' + end + + repo = Git.init(@project) + repo.add('.') + repo.commit('Initial commit') + end + + context "and the files defaults are used" do + setup do + @gemspec = build_jeweler_gemspec + @gemspec.set_jeweler_defaults(@project, @project) + end + + should "populate files from git" do + assert_equal %w(Rakefile lib/example.rb), @gemspec.files + end + end + + context "and the files specified manually" do + setup do + @gemspec = build_jeweler_gemspec do |gemspec| + gemspec.files = %w(Rakefile) end + @gemspec.set_jeweler_defaults(@project, @project) end + + should "not be overridden by files from git" do + assert_equal %w(Rakefile), @gemspec.files + end end - should "allow the user to concat files to the existing `files' array" do - before = @spec.files.dup - @spec.files << 'extra' + end - assert_equal before + %w{ extra }, @spec.files + context "there are some files and is setup for git with ignored files" do + setup do + @project.file '.gitignore', 'ignored' + @project.file 'ignored' + @project.file 'Rakefile' + @project.directory('lib') do |lib| + lib.file 'example.rb' + end + + repo = Git.init(@project) + repo.add('.') + repo.commit('Initial commit') + + + @gemspec = build_jeweler_gemspec + @gemspec.set_jeweler_defaults(@project, @project) + end + + should "populate files from git excluding ignored" do + assert_equal %w(.gitignore Rakefile lib/example.rb), @gemspec.files + end + end + + context "there are some files and is setup for git and working in a sub directory" do + setup do + @subproject = File.join(@project, 'subproject') + @project.file 'Rakefile' + @project.file 'README' + @project.directory 'subproject' do |subproject| + subproject.file 'README' + subproject.directory('lib') do |lib| + lib.file 'subproject_example.rb' + end + end + + repo = Git.init(@project) + repo.add('.') + repo.commit('Initial commit') + + @gemspec = build_jeweler_gemspec + @gemspec.set_jeweler_defaults(@subproject, @project) + end + + should "populate files from git relative to sub directory" do + assert_equal %w(lib/subproject_example.rb README).sort, @gemspec.files.sort + end + end + + context "there are some files and is not setup for git" do + setup do + @project.file 'Rakefile' + @project.directory('lib') do |lib| + lib.file 'example.rb' + end + + @gemspec = build_jeweler_gemspec + @gemspec.set_jeweler_defaults(@project, @project) + end + + should "not populate files" do + assert_equal [], @gemspec.files.sort end end end