Sha256: 4b2aa330d16468aa67d479f2d9b587dc809d9d7c6b190bea258036213b510baf

Contents?: true

Size: 1.63 KB

Versions: 3

Compression:

Stored size: 1.63 KB

Contents

require 'test_helper'

class CLI < MiniTest::Unit::TestCase

  def setup
    @templates_path = "#{File.dirname(__FILE__)}/../lib/sinatra_generator/templates"
    @tmp_dir = Dir.mktmpdir
    Dir.chdir @tmp_dir
  end

  def teardown
    Dir.chdir('..')
    FileUtils.remove_entry @tmp_dir
  end

  # sinatra new blog
  def test_command_new
    SinatraGenerator::CLI.start ['new','blog']
    assert File.directory? "blog"

    Dir.chdir 'blog' do
      assert File.exist?('main.rb'), 'main.rb not found'
      assert File.exist?('Gemfile'), 'Gemfile not found'
      assert File.exist?('config.ru'), 'config.ru not found'
    end
  end

  # sinatra new blog -p
  def test_option_profile
    SinatraGenerator::CLI.start ['new','blog', '-p']
    Dir.chdir 'blog' do
      assert_equal File.read('Procfile'), File.read("#{@templates_path}/Procfile")
    end
  end

  # sinatra new blog -v
  def test_option_views
    SinatraGenerator::CLI.start ['new','blog', '-v']
    Dir.chdir 'blog' do
      assert File.directory?('views'), 'views not found'
      assert_includes File.read('main.rb'), "erb :index"
      Dir.chdir 'views' do
        assert_equal File.read('index.erb'), File.read("#{@templates_path}/index.erb")
      end
    end
  end  

  # sinatra new blog -av
  def test_option_assets_with_views
    SinatraGenerator::CLI.start ['new','blog', '-av']
    Dir.chdir 'blog' do
      assert File.directory?('public'), 'public not found'
      assert File.directory?('views'), 'views not found'

      Dir.chdir 'views' do
        assert_match /\n\s\s<link rel='stylesheet' href='\/stylesheets\/main.css'>/, File.read('layout.erb')
      end      
    end
  end  

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sinatra_generator-0.1.4 test/cli_test.rb
sinatra_generator-0.1.3 test/cli_test.rb
sinatra_generator-0.1.2 test/cli_test.rb