Class: ScrewUnit::Representations::Spec

Inherits:
JsTestCore::Representations::Spec
  • Object
show all
Defined in:
lib/screw_unit/representations/spec.html.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.jquery_js_fileObject



5
6
7
# File 'lib/screw_unit/representations/spec.html.rb', line 5

def jquery_js_file
  @jquery_js_file ||= "/core/jquery-1.3.2.js"
end

Instance Method Details

#body_contentObject



114
115
116
# File 'lib/screw_unit/representations/spec.html.rb', line 114

def body_content
  div :id => "screw_unit_content"
end

#core_js_filesObject



100
101
102
103
104
105
106
107
108
# File 'lib/screw_unit/representations/spec.html.rb', line 100

def core_js_files
  script :src => jquery_js_file
  script :src => "/core/jquery.fn.js"
  script :src => "/core/jquery.print.js"
  script :src => "/core/screw.builder.js"
  script :src => "/core/screw.matchers.js"
  script :src => "/core/screw.events.js"
  script :src => "/core/screw.behaviors.js"
end

#head_contentObject



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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/screw_unit/representations/spec.html.rb', line 16

def head_content
  core_js_files
  script(raw(<<-JS), :type => "text/javascript")
    (function($) {
      Screw.Assets = {};
      Screw.Assets.use_cache_buster = false; // TODO: NS/CTI - make this configurable from the UI.
      var required_paths = [];
      var included_stylesheets = {};
      var cache_buster = parseInt(new Date().getTime()/(1*1000));

      function tag(name, attributes) {
        var html = "<" + name;
        for(var attribute in attributes) {
          html += (" " + attribute + "='" + attributes[attribute]) + "'";
        };
        html += "></";
        html += name;
        html += ">";
        return html;
      }

      Screw.Assets.require = function(javascript_path, onload) {
        if(!required_paths[javascript_path]) {
          var full_path = javascript_path + ".js";
          if (Screw.Assets.use_cache_buster) {
            full_path += '?' + cache_buster;
          }
          document.write(tag("script", {src: full_path, type: 'text/javascript'}));
          if(onload) {
            var scripts = document.getElementsByTagName('script');
            scripts[scripts.length-1].onload = onload;
          }
          required_paths[javascript_path] = true;
        }
      };

      Screw.Assets.stylesheet = function(stylesheet_path) {
        if(!included_stylesheets[stylesheet_path]) {
          var full_path = stylesheet_path + ".css";
          if(Screw.Assets.use_cache_buster) {
            full_path += '?' + cache_buster;
          }
          document.write(tag("link", {rel: 'stylesheet', type: 'text/css', href: full_path}));
          included_stylesheets[stylesheet_path] = true;
        }
      };

      window.require = Screw.Assets.require;
      window.stylesheet = Screw.Assets.stylesheet;
    })(jQuery);

    (function($) {
      var ajax = $.ajax;
      $(Screw).bind('after', function() {
        var error_text = $(".error").map(function(i, error_element) {
          var element = $(error_element);

          var parent_descriptions = element.parents("li.describe");
          var parent_description_text = [];

          for(var i=parent_descriptions.length-1; i >= 0; i--) {
            parent_description_text.push($(parent_descriptions[i]).find("h1").text());
          }

          var it_text = element.parents("li.it").find("h2").text();

          return parent_description_text.join(" ") + " " + it_text + ": " + element.text();
        }).get().join("\\n");

        ajax({
          type: "POST",
          url: '#{ScrewUnit::Resources::SeleniumSession.path("/finish")}',
          data: {"text": error_text, "session_id": '#{session_id}'}
        });
      });
    })(jQuery);
  JS
  project_js_files
  link :rel => "stylesheet", :href => "/core/screw.css"
  project_css_files

  spec_script_elements
end

#jquery_js_fileObject



110
111
112
# File 'lib/screw_unit/representations/spec.html.rb', line 110

def jquery_js_file
  self.class.jquery_js_file
end

#title_textObject



12
13
14
# File 'lib/screw_unit/representations/spec.html.rb', line 12

def title_text
  "Screw Unit suite"
end