require 'spec_helper' describe Packr::Rails do include RailsProjectSpecHelpers # before do # @js_path = { # :a => fixture_path("rails_project/app/assets/javascripts/test_a.js"), # :b => fixture_path("rails_project/app/assets/javascripts/test_b.js.packr") # } # @js_source = { # :a => File.read(@js_path[:a]).to_s, # :b => File.read(@js_path[:b]).to_s # } # end describe "VERSION" do it 'should be defined' do defined?(::Packr::Rails::VERSION) end it 'should be a valid version string (e.g. "0.0.1", or "0.0.1.rc1")' do valid_version_string = /^\d+\.\d+\.\d+/ Packr::Rails::VERSION.must_match valid_version_string end end describe "Compressor" do it 'should be defined' do Packr::Rails::Compressor.must_be_kind_of Class end it 'should compress using Packr' do js_path = fixture_path("rails_project/app/assets/javascripts/test_a.js") js_source = File.read(js_path) compressor = Packr::Rails::Compressor.new compressor.expects(:compress_options).returns(::Packr::Rails::Railtie::DEFAULTS[:pack_options]) packed_js_via_compressor = compressor.compress(js_source) packed_js_via_compressor.must_equal Packr.pack(js_source, ::Packr::Rails::Railtie::DEFAULTS[:pack_options]) end end describe "Template" do it 'should be defined' do Packr::Rails::Template.must_be_kind_of Class end end describe "Railtie" do it 'should be defined' do Packr::Rails::Railtie.must_be_kind_of Class end end describe "Integration" do it "should integrate with sprockets correctly" do filename = 'test_a.js' js_output = within_rails_app("rails_project") do runcmd "ruby script/rails runner 'puts Rails.application.assets[#{filename.inspect}]'" end js_output.must_match(/#{Regexp.escape("A.hello")}/) end it 'should compress using the optional JS compressor' do js_path = fixture_path("rails_project/app/assets/javascripts/test_a.js") js_source = File.read(js_path) js_output = Packr::Rails::Compressor.new.compress(js_source) js_output.must_equal Packr.pack(js_source) end end end