drnic (owner)

Fork Of

Revisions

gist: 149239 Download_button fork
public
Public Clone URL: git://gist.github.com/149239.git
Embed All Files: show embed
add_data_spec.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
require("spec_helper.js");
require("../../public/javascripts/add_data.js");
 
Screw.Unit(function(){
  describe("AddData", function(){
    
    describe('adding rows', function() {
 
      ...snip...
 
    });
    
  });
});
 
add_data_spec.rb #
1
2
3
4
5
6
7
8
9
10
require "#{File.dirname(__FILE__)}/javascript_spec_helper"
 
run_javascript_spec(:add_data, "/data_points/new.html.erb") do
  @current_user = User.make
  @current_account = Account.make
  @current_account.data_types << DataType.make(:name => 'Profit')
  @current_account.data_types << DataType.make(:name => 'Revenue')
  template.stub!(:current_user).and_return(@current_user)
  template.stub!(:current_account).and_return(@current_account)
end
javascript_spec_helper.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require "#{File.dirname(__FILE__)}/../spec_helper"
 
def run_javascript_spec(name, view, &setup)
  plugin_prefix = "#{RAILS_ROOT}/vendor/plugins/blue-ridge"
  rhino_command = "java -jar #{plugin_prefix}/lib/js.jar -w -debug"
  test_runner_command = "#{rhino_command} #{plugin_prefix}/lib/test_runner.js"
 
  html_layout = lambda { |body|
    <<-HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 
<head>
<title>Application | JavaScript Testing Results</title>
<link rel="stylesheet" href="screw.css" type="text/css" charset="utf-8" />
<script type="text/javascript" src="../../../vendor/plugins/blue-ridge/lib/blue-ridge.js"></script>
</head>
 
<body>
<!-- Put any HTML fixture elements here. -->
#{body}
</body>
</html>
HTML
  }
 
  describe view, :type => :view do
    before(&setup)
 
    it "should pass javascript tests" do
      render
      File.open(File.join(File.dirname(__FILE__), "fixtures/#{name}.html"), 'w') do |f|
        f.write html_layout.call(response.body)
      end
      Dir.chdir(File.join(File.dirname(__FILE__))) do
        puts "\n"
        unless system("#{test_runner_command} #{name}_spec.js")
          flunk "javascript test failure"
        end
      end
    end
  end
end