Sha256: c56df10b243445eb509890973bcdc8976012f608840264608a30ed1846c092f8

Contents?: true

Size: 1.77 KB

Versions: 1

Compression:

Stored size: 1.77 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper'))

module JsTestDriver
  class HtmlFixtureTest < Test::Unit::TestCase

    def fixture_for_dir(dir)
      JsTestDriver::HtmlFixture.new(dir)
    end

    def test_given_a_made_up_fixture_directory_should_return_an_empty_hash
      # given
      fixture = fixture_for_dir('/xxx/yyy/zzz')

      # then
      assert_equal({}, fixture.to_h)
    end

    def file_contents(fixture_name)
      return File.read(File.join(fixture_dir, "#{fixture_name}.html"))
    end

    def known_fixtures
      %w{ a b c foo/a foo/bar/a baz/a }
    end

    def test_should_return_all_of_the_html_files_in_fixture_directory
      # given
      fixture = fixture_for_dir(fixture_dir)

      # then
      assert_equal known_fixtures.sort, fixture.to_h.keys.sort
    end

    def test_should_have_the_right_contents_for_every_fixture_file
      # given
      fixture = fixture_for_dir(fixture_dir)

      # then
      known_fixtures.each do |name|
        assert_equal file_contents(name), fixture.to_h[name], "The contents of the fixture '#{name}' differ"  
      end
    end

    def fixture_named(name, namespace)
      JsTestDriver::HtmlFixture.new('/some/bogus/directory', name, namespace)
    end

    def assert_contains(expected, actual)
      assert_not_nil actual
      assert actual.include?(expected), "Expected:\n#{actual}\nto include:\n#{expected}"
    end

    def test_should_initialize_the_namespace
      # given
      fixture = fixture_named('foo', 'ns')

      # then
      assert_contains "if (typeof(ns) !== 'undefined') { ns = {}; }", fixture.to_s
    end

    def test_should_set_the_fixture
      # given
      fixture = fixture_named('foo', 'ns')

      # then
      assert_contains "ns.foo = {};", fixture.to_s
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
js-test-driver-rails-0.2.7 test/unit/html_fixture_test.rb