Sha256: 7267798587d2161466c1eb4e6d74dcf9c80bf481eeabc5523240e467f7f97ef0

Contents?: true

Size: 1.65 KB

Versions: 4

Compression:

Stored size: 1.65 KB

Contents

require File.dirname(__FILE__) + "/../../lib/roger_requirejs/processor"
require "test/unit"

class ProcessorTest < Test::Unit::TestCase

  def test_require_js_default_fallback
    # When the user points the requirejs processer to a wrong file
    # it should throw an RunTimeError
    options = {:rjs => "s.js"}
    requirejs_processor = RogerRequirejs::Processor.new(options)
    rjs = options[:rjs]

    rjs_command = ''

    assert_raise RuntimeError do
      # The file does is there - it's this one, so it should raise
      rjs_command = requirejs_processor.rjs_check
    end

    # No command string is returned
    assert_equal rjs_command, ""
    
  end
  
  def test_require_js_bin
    # When no default require.js path is given we expect it to be r.js availble in $PATH
    requirejs_processor = RogerRequirejs::Processor.new
    rjs = "r.js" # Default r.js by npm

    begin
      `#{rjs} -v`
    rescue Errno::ENOENT
      assert_raise RuntimeError do
        requirejs_processor.rjs_check
      end
    else
      assert_equal requirejs_processor.rjs_check, rjs
    end
    
  end
  
  def test_require_js_lib
    # Just point options[:rjs] to a file to look if its there,
    # the user is expected to point to a correct r.js file if he
    # doesn't want to use the r.js shipped with npm
    options = {:rjs => __FILE__}
    requirejs_processor = RogerRequirejs::Processor.new(options)
    rjs = options[:rjs]

    rjs_command = ''

    assert_nothing_raised RuntimeError do
      # The file  is there - it's this one in fact, so it shouldn't raise
      rjs_command = requirejs_processor.rjs_check
    end

    assert_equal rjs_command, "node #{rjs}"
    
  end
  
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
roger_requirejs-1.1.2 test/unit/processor_test.rb
roger_requirejs-1.1.1 test/unit/processor_test.rb
roger_requirejs-1.1.0 test/unit/processor_test.rb
roger_requirejs-1.0.0 test/unit/processor_test.rb