This repository has been archived by the owner on Jun 10, 2018. It is now read-only.
forked from rails/sprockets
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for Sprockets::Environment
- Loading branch information
Sam Stephenson
committed
May 29, 2008
1 parent
0b427dc
commit f1eeca3
Showing
6 changed files
with
89 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
var FooFoo = { }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
require "test_helper" | ||
|
||
class EnvironmentTest < Test::Unit::TestCase | ||
def test_load_path_locations_become_pathnames_for_absolute_locations_from_the_root | ||
environment = Sprockets::Environment.new("/root", ["/a", "b"]) | ||
assert_load_path_equals ["/a", "/root/b", "/root"], environment | ||
end | ||
|
||
def test_pathname_from_for_location_with_leading_slash_should_return_a_pathname_with_the_location_unchanged | ||
environment = Sprockets::Environment.new("/root") | ||
assert_absolute_location "/a", environment.pathname_from("/a") | ||
end | ||
|
||
def test_pathname_from_for_relative_location_should_return_a_pathname_for_the_expanded_absolute_location_from_root | ||
environment = Sprockets::Environment.new("/root") | ||
assert_absolute_location "/root/a", environment.pathname_from("a") | ||
assert_absolute_location "/root/a", environment.pathname_from("./a") | ||
assert_absolute_location "/a", environment.pathname_from("../a") | ||
end | ||
|
||
def test_register_load_location_should_unshift_the_location_onto_the_load_path | ||
environment = Sprockets::Environment.new("/root") | ||
environment.register_load_location("a") | ||
assert_load_path_equals ["/root/a", "/root"], environment | ||
environment.register_load_location("b") | ||
assert_load_path_equals ["/root/b", "/root/a", "/root"], environment | ||
end | ||
|
||
def test_register_load_location_should_remove_already_existing_locations_before_unshifting | ||
environment = Sprockets::Environment.new("/root") | ||
environment.register_load_location("a") | ||
environment.register_load_location("b") | ||
assert_load_path_equals ["/root/b", "/root/a", "/root"], environment | ||
environment.register_load_location("a") | ||
assert_load_path_equals ["/root/a", "/root/b", "/root"], environment | ||
end | ||
|
||
def test_find_should_return_the_first_matching_pathname_in_the_load_path | ||
environment = environment_for_fixtures | ||
first_pathname = environment.find("foo.js") | ||
assert_absolute_location_ends_with "src/foo.js", first_pathname | ||
|
||
environment.register_load_location(File.join(FIXTURES_PATH, "src", "foo")) | ||
second_pathname = environment.find("foo.js") | ||
assert_not_equal first_pathname, second_pathname | ||
assert_absolute_location_ends_with "foo/foo.js", second_pathname | ||
end | ||
|
||
def test_find_should_return_nil_when_no_matching_source_file_is_found | ||
environment = environment_for_fixtures | ||
assert_nil environment.find("nonexistent.js") | ||
end | ||
|
||
protected | ||
def assert_absolute_location(location, pathname) | ||
assert_equal location, pathname.absolute_location | ||
end | ||
|
||
def assert_load_path_equals(load_path_absolute_locations, environment) | ||
assert load_path_absolute_locations.zip(environment.load_path).map { |location, pathname| location == pathname.absolute_location }.all? | ||
end | ||
|
||
def assert_absolute_location_ends_with(location_ending, pathname) | ||
assert pathname.absolute_location[/#{Regexp.escape(location_ending)}$/] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters