Sha256: 5387f6bc4bc9c1fbeaa0e8d8e69224745d20bbf5c79179ad9278fa906b826581

Contents?: true

Size: 1.79 KB

Versions: 3

Compression:

Stored size: 1.79 KB

Contents

require "test_helper"

class TestJsLint < Test::Unit::TestCase
  def initialize(*args)
    @path = File.expand_path(path("../bin"))
    @file = path("jsltest.js")
    super
  end

  def setup
    FileUtils.mkdir(path("")) unless File.exists?(path(""))
    File.open(@file, "w") { |f| f.puts "" }
  end

  def teardown
    File.delete(@file)
  end

  context "verifying file with jslint" do
    should "shell out to rhino/jslint" do
      jslint = Juicer::JsLint.new(:bin_path => @path)
      jslint.expects(:execute).with("-jar \"#{@path}/rhino1_7R3.jar\" \"#{@path}/jslint-1.0.js\" \"#{@file}\"").returns("jslint: No problems")

      assert jslint.check(@file).ok?
    end
  end

  context "jslint report returns" do
    should "be a report object for valid files" do
      jslint = Juicer::JsLint.new(:bin_path => @path)
      jslint.expects(:execute).returns("jslint: No problems")

      assert_equal Juicer::JsLint::Report, jslint.check(@file).class
    end

    should "be a report object for invalid files" do
      jslint = Juicer::JsLint.new(:bin_path => @path)
      jslint.expects(:execute).returns("Wrong use of semicolon\nWrong blabla")

      assert_equal Juicer::JsLint::Report, jslint.check(path("not-ok.js")).class
    end
  end

  context "errors" do
    should "be available on report" do
      jslint = Juicer::JsLint.new(:bin_path => @path)
      jslint.expects(:execute).returns("Wrong use of semicolon\nWrong blabla\nWrong use of semicolon\nWrong blabla")

      assert_equal 2, jslint.check(@file).errors.length
    end

    should "be error objects" do
      jslint = Juicer::JsLint.new(:bin_path => @path)
      jslint.expects(:execute).returns("Wrong use of semicolon\nWrong blabla")

      error = jslint.check(@file).errors.first
      assert_equal Juicer::JsLint::Error, error.class
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
juicer-1.0.16 test/unit/juicer/jslint_test.rb
juicer-1.0.15 test/unit/juicer/jslint_test.rb
juicer-1.0.14 test/unit/juicer/jslint_test.rb