<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -37,6 +37,13 @@ function:
   response.should call_js('fn(true)')
   response.should call_js('gApp.setup')
 
+If there is a body, the arguments to the call are parsed (as JSON) and
+passed to it:
+  # response includes &lt;script&gt;...fn('string', 2)...&lt;/script&gt;
+  response.should call_js(fn') do |args|
+    args.should == ['string', 2]
+  end
+
 
 = License
 Copyright 2008 by Oliver Steele.  All rights reserved.</diff>
      <filename>README</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,5 @@
 require 'rake/rdoctask'
+require 'spec/rake/spectask'
 
 desc 'Generate documentation for the plugin.'
 Rake::RDocTask.new(:rdoc) do |rdoc|
@@ -8,3 +9,13 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
     '--main' &lt;&lt; 'README'
   rdoc.rdoc_files.include ['lib', 'README', 'TODO', 'MIT-LICENSE']
 end
+
+desc &quot;Run all specs&quot;
+Spec::Rake::SpecTask.new do |t|
+  t.spec_files = FileList['spec/*_spec.rb']
+  if ENV['RCOV']
+    t.rcov = true
+    t.rcov_dir = '../doc/output/coverage'
+    t.rcov_opts = ['--exclude', 'spec\/spec']
+  end
+end</diff>
      <filename>Rakefile</filename>
    </modified>
    <modified>
      <diff>@@ -2,7 +2,6 @@
 
 Next:
 - view helper
-- call_js body
 - ignore framework files in public/javascript
 
 
@@ -13,13 +12,3 @@ Use RJS inside a view:
     page &lt;&lt; &quot;alert('JavaScript with Prototype.');&quot;
     page.call 'alert', 'My message!'
   end
-
-
-== 'Calls JavaScript' RSpec Matcher
-  # requires &quot;MyClass.fn(1, {key: 'substring'}) inside
-  # a &lt;script&gt;...&lt;/script&gt; or +javascript_tag+:
-  call_js('MyClass.fn') do |args|
-    args.first.should == 1
-    args.second.should be_instance_of(Hash)
-    args.second['key'].should =~ /substr/
-  end</diff>
      <filename>TODO</filename>
    </modified>
    <modified>
      <diff>@@ -12,10 +12,10 @@ module JavascriptFu
                      pattern = /\b#{pattern}/
                    when pattern =~ /^new\b/
                      # 'new': the arglist is optional
-                     pattern = /\b#{pattern}\b\s*(\(.*)?/
+                     pattern = /\b#{pattern}\b\s*\((.*)?/
                    else
                      # else the arglist is required
-                     pattern = /\b#{pattern}\s*(\(.*)/
+                     pattern = /\b#{pattern}\s*\((.*)/
                    end
       end
       
@@ -30,7 +30,13 @@ module JavascriptFu
           actual = HTML::Document.new(response_or_text).root
         end
         begin
-          @spec_scope.assert_select(actual, 'script', @pattern, &amp;block)
+          @spec_scope.assert_select(actual, 'script', @pattern) do |tags|
+            if block
+              raise &quot;no arguments detected&quot; unless tags[0].to_s =~ @pattern
+              args = JavascriptFu.read_json_arglist($1)
+              block.call(args)
+            end
+          end
         rescue ::Test::Unit::AssertionFailedError =&gt; @error
         end
         
@@ -61,13 +67,36 @@ module JavascriptFu
     #   response.should call_js('new C')
     #   response.should call_js('new C(1)')
     #
+    # If block is supplied, the arguments to the function are decoded
+    # as JSON and passed to the block:
+    #   # response includes &lt;script&gt;...fn('string', 2)...&lt;/script&gt;
+    #   response.should call_js(fn') do |args|
+    #     args.should == ['string', 2]
+    #   end
     def call_js(pattern, &amp;block)
       return CallJS.new(pattern, self, &amp;block)
-      # only look in script tags
-      have_tag('script', pattern)
-      if block
-        p self
+    end
+  end
+  
+  # Parse until the first unmatched &quot;)]}&quot; or end of string
+  def self.read_json_arglist(string)
+    require 'activesupport'
+    scanner, level = StringScanner.new(string), 0
+    while scanner.scan_until(/(['&quot;\/(){}\[\]])/)
+      token = scanner[1]
+      break if token =~ /[)}\]]/ and level == 0
+      case token
+      when /[({\[]/
+        level += 1
+      when /[)}\]]/
+        level -= 1
+      when /'/
+      when /&quot;/
+      else
+        raise &quot;unimplemented&quot;
       end
     end
+    string = string[0...scanner.pos-1] if scanner.pos &gt; 0
+    ActiveSupport::JSON.decode('[' + string + ']')
   end
 end</diff>
      <filename>lib/js_matchers.rb</filename>
    </modified>
    <modified>
      <diff>@@ -59,10 +59,30 @@ describe :call_js do
   
   describe &quot;argument list parsing&quot; do
     it &quot;should match the arguments of a function call&quot; do
-      pending
       string = '&lt;script&gt;fname(&quot;string&quot;, 2)&lt;/script&gt;'
       string.should call_js('fname') do |args|
-        p args[0].to_s
+        args.should == ['string', 2]
+      end
+    end
+    
+    it &quot;should match the arguments of a method call&quot; do
+      string = '&lt;script&gt;obj.fname(&quot;string&quot;, 2)&lt;/script&gt;'
+      string.should call_js('obj.fname') do |args|
+        args.should == ['string', 2]
+      end
+    end
+    
+    it &quot;should ignore following material&quot; do
+      string = '&lt;script&gt;fname(&quot;string&quot;, 2);g()&lt;/script&gt;'
+      string.should call_js('fname') do |args|
+        args.should == ['string', 2]
+      end
+    end
+    
+    it &quot;should include nested objects&quot; do
+      string = '&lt;script&gt;fname(&quot;string&quot;, [1,2], {a:3})&lt;/script&gt;'
+      string.should call_js('fname') do |args|
+        args.should == ['string', [1,2], {'a' =&gt; 3}]
       end
     end
   end</diff>
      <filename>spec/javascript_matchers_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>56a119ddbe0fb13787156ae3e21d37c8ff492c6e</id>
    </parent>
  </parents>
  <author>
    <name>Oliver Steele</name>
    <email>steele@osteele.com</email>
  </author>
  <url>http://github.com/osteele/javascript_fu/commit/822e3df9ce6f5905bb94e89bbc709b2da5c84515</url>
  <id>822e3df9ce6f5905bb94e89bbc709b2da5c84515</id>
  <committed-date>2008-04-14T07:07:03-07:00</committed-date>
  <authored-date>2008-04-14T07:07:03-07:00</authored-date>
  <message>parse arguments</message>
  <tree>21830a8c54257d4f38eb3cb3a67967ad8283232d</tree>
  <committer>
    <name>Oliver Steele</name>
    <email>steele@osteele.com</email>
  </committer>
</commit>
