Skip to content
Browse files

Allow loading multiple files at once

  • Loading branch information...
1 parent e9cebf0 commit b1cce9b8ff865afba66a72f4bc363c4ef4651dd1 @mynyml committed
Showing with 35 additions and 6 deletions.
  1. +7 −6 lib/harmony/page.rb
  2. +28 −0 test/page_test.rb
View
13 lib/harmony/page.rb
@@ -65,15 +65,16 @@ def initialize(document=nil)
@window = Window.from_document(document) if document
end
- # Load a javascript file in page's context
- #
- # @param [String] path
- # path to js file
+ # Load one or more javascript files in page's context
#
+ # @param [#to_s, #to_s, ...] paths
+ # paths to js file
# @return [Page] self
#
- def load(path)
- window.load(path.to_s)
+ def load(*paths)
+ paths.flatten.each do |path|
+ window.load(path.to_s)
+ end
self
end
View
28 test/page_test.rb
@@ -65,6 +65,34 @@ class PageTest < MiniTest::Unit::TestCase
assert_equal 'bar', page.x('foo()')
end
+ test "can load multiple files as array" do
+ paths = []
+ paths << tempfile(<<-HTML)
+ function foo() { return 'bar' };
+ HTML
+ paths << tempfile(<<-HTML)
+ function moo() { return 'boo' };
+ HTML
+
+ page = Page.new.load(paths)
+ assert_equal 'bar', page.x('foo()')
+ assert_equal 'boo', page.x('moo()')
+ end
+
+ test "can load multiple files as splat" do
+ paths = []
+ paths << tempfile(<<-HTML)
+ function foo() { return 'bar' };
+ HTML
+ paths << tempfile(<<-HTML)
+ function moo() { return 'boo' };
+ HTML
+
+ page = Page.new.load(*paths)
+ assert_equal 'bar', page.x('foo()')
+ assert_equal 'boo', page.x('moo()')
+ end
+
private
def tempfile(content)
Tempfile.open('abc') {|f| f << content; @__path = f.path }

0 comments on commit b1cce9b

Please sign in to comment.
Something went wrong with that request. Please try again.