Skip to content

Commit

Permalink
WIP not getting anywhere with js tests
Browse files Browse the repository at this point in the history
[#27]
  • Loading branch information
alxndr committed Oct 5, 2014
1 parent 8e423c0 commit d193b93
Show file tree
Hide file tree
Showing 9 changed files with 249 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -37,7 +37,7 @@ group :development, :test do
gem 'guard'
gem 'guard-rails'
gem 'guard-rspec'
gem 'jasmine-rails'
gem 'jasmine'
gem 'launchy' # needed for capybara's save_and_open_page
gem 'rspec-rails'
gem 'shoulda-matchers'
Expand Down
12 changes: 6 additions & 6 deletions Gemfile.lock
Expand Up @@ -134,12 +134,12 @@ GEM
json (~> 1.8)
multi_xml (>= 0.5.2)
i18n (0.6.11)
jasmine-core (2.0.2)
jasmine-rails (0.10.2)
jasmine-core (>= 1.3, < 3.0)
jasmine (2.0.3)
jasmine-core (~> 2.0.0)
phantomjs
railties (>= 3.1.0)
sprockets-rails
rack (>= 1.2.1)
rake
jasmine-core (2.0.2)
json (1.8.1)
kgio (2.9.2)
launchy (2.4.2)
Expand Down Expand Up @@ -306,7 +306,7 @@ DEPENDENCIES
guard-rails
guard-rspec
htmlentities
jasmine-rails
jasmine
launchy
neat
newrelic_rpm (>= 3.5.3.25)
Expand Down
1 change: 0 additions & 1 deletion config/jasmine.yml

This file was deleted.

Empty file.
155 changes: 155 additions & 0 deletions spec/javascripts/support/jasmine-require-boot.js
@@ -0,0 +1,155 @@
/*
Copyright (c) 2008-2014 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
Starting with version 2.0, this file "boots" Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's specs. This file should be loaded after `jasmine.js`, but before any project source files or spec files are loaded. Thus this file can also be used to customize Jasmine for a project.
If a project is using Jasmine via the standalone distribution, this file can be customized directly. If a project is using Jasmine via the [Ruby gem][jasmine-gem], this file can be copied into the support directory via `jasmine copy_boot_js`. Other environments (e.g., Python) will have different mechanisms.
The location of `boot.js` can be specified and/or overridden in `jasmine.yml`.
[jasmine-gem]: http://github.com/pivotal/jasmine-gem
*/

(function() {

/**
* ## Require &amp; Instantiate
*
* Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
*/
window.jasmine = jasmineRequire.core(jasmineRequire);

/**
* Since this is being run in a browser and the results should populate to an HTML page, require the HTML-specific Jasmine code, injecting the same reference.
*/
jasmineRequire.html(jasmine);

/**
* Create the Jasmine environment. This is used to run all specs in a project.
*/
var env = jasmine.getEnv();

/**
* ## The Global Interface
*
* Build up the functions that will be exposed as the Jasmine public interface. A project can customize, rename or alias any of these functions as desired, provided the implementation remains unchanged.
*/
var jasmineInterface = jasmineRequire.interface(jasmine, env);

/**
* Add all of the Jasmine global/public interface to the proper global, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`.
*/
if (typeof window == "undefined" && typeof exports == "object") {
extend(exports, jasmineInterface);
} else {
extend(window, jasmineInterface);
}

/**
* ## Runner Parameters
*
* More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface.
*/

var queryString = new jasmine.QueryString({
getWindowLocation: function() { return window.location; }
});

var catchingExceptions = queryString.getParam("catch");
env.catchExceptions(typeof catchingExceptions === "undefined" ? true : catchingExceptions);

/**
* ## Reporters
* The `HtmlReporter` builds all of the HTML UI for the runner page. This reporter paints the dots, stars, and x's for specs, as well as all spec names and all failures (if any).
*/
var htmlReporter = new jasmine.HtmlReporter({
env: env,
onRaiseExceptionsClick: function() { queryString.setParam("catch", !env.catchingExceptions()); },
getContainer: function() { return document.body; },
createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); },
timer: new jasmine.Timer()
});

/**
* The `jsApiReporter` also receives spec results, and is used by any environment that needs to extract the results from JavaScript.
*/
env.addReporter(jasmineInterface.jsApiReporter);
env.addReporter(htmlReporter);

/**
* Filter which specs will be run by matching the start of the full name against the `spec` query param.
*/
var specFilter = new jasmine.HtmlSpecFilter({
filterString: function() { return queryString.getParam("spec"); }
});

env.specFilter = function(spec) {
return specFilter.matches(spec.getFullName());
};

/**
* Setting up timing functions to be able to be overridden. Certain browsers (Safari, IE 8, phantomjs) require this hack.
*/
window.setTimeout = window.setTimeout;
window.setInterval = window.setInterval;
window.clearTimeout = window.clearTimeout;
window.clearInterval = window.clearInterval;

/**
* ## Execution
*/

// http://community.spiceworks.com/blogs/developers/1717-setting-up-rails-jasmine-2-0-and-requirejs
var specs = JSON.parse(document.querySelector('#specs').innerHTML);
console.log("specs....", specs);

require(specs, function () {
htmlReporter.initialize();
env.execute();
});

/**
* ## Execution
*
* Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded.
*/
//var currentWindowOnload = window.onload;

//window.onload = function() {
//if (currentWindowOnload) {
//currentWindowOnload();
//}
//htmlReporter.initialize();
//env.execute();
//};

/**
* Helper function for readability above.
*/
function extend(destination, source) {
for (var property in source) destination[property] = source[property];
return destination;
}

}());
22 changes: 22 additions & 0 deletions spec/javascripts/support/jasmine-require-config.js
@@ -0,0 +1,22 @@
/* global require */

(function() {
'use strict';

require.config({
baseUrl: '/assets',
paths: {
'jasmine': '../__jasmine__/jasmine',
'jasmine-html': '../__jasmine__/jasmine-html'
},
shim: {
'jasmine': {
"exports": 'jasmine'
},
'jasmine-html': {
"deps": ['jasmine'],
"exports": 'jasmine'
}
}
});
})();
56 changes: 6 additions & 50 deletions spec/javascripts/support/jasmine.yml
@@ -1,50 +1,6 @@
# path to parent directory of src_files
# relative path from Rails.root
# defaults to app/assets/javascripts
src_dir: "app/assets/javascripts"

# path to additional directory of source file that are not part of assets pipeline and need to be included
# relative path from Rails.root
# defaults to []
# include_dir:
# - ../mobile_app/public/js

# path to parent directory of css_files
# relative path from Rails.root
# defaults to app/assets/stylesheets
css_dir: "app/assets/stylesheets"

# list of file expressions to include as source files
# relative path from src_dir
src_files:
- "application.{js.coffee,js,coffee}"

# list of file expressions to include as css files
# relative path from css_dir
css_files:

# path to parent directory of spec_files
# relative path from Rails.root
#
# Alternatively accept an array of directory to include external spec files
# spec_dir:
# - spec/javascripts
# - ../engine/spec/javascripts
#
# defaults to spec/javascripts
spec_dir: spec/javascripts

# list of file expressions to include as helpers into spec runner
# relative path from spec_dir
helpers:
- "helpers/**/*.{js.coffee,js,coffee}"

# list of file expressions to include as specs into spec runner
# relative path from spec_dir
spec_files:
- "**/*[Ss]pec.{js.coffee,js,coffee}"

# path to directory of temporary files
# (spec runner and asset cache)
# defaults to tmp/jasmine
tmp_dir: "tmp/jasmine"
src_files: []
boot_dir: spec/javascripts/support
boot_files:
- '../assets/require.js'
- 'jasmine-require-config.js'
- 'jasmine-require-boot.js'
33 changes: 33 additions & 0 deletions spec/javascripts/support/jasmine_helper.rb
@@ -0,0 +1,33 @@
module Jasmine
def self.runner_template
File.read(File.join(File.dirname(__FILE__), "run.html.erb"))
end

class Configuration
def js_files
map(@jasmine_files, :jasmine) +
map(@boot_files, :boot) +
map(@runner_boot_files, :runner_boot) +
map(@src_files, :src)
end

def spec_files
map(@spec_files, :spec)
end
end
end
#Use this file to set/override Jasmine configuration options
#You can remove it if you don't need it.
#This file is loaded *after* jasmine.yml is interpreted.
#
#Example: using a different boot file.
#Jasmine.configure do |config|
# config.boot_dir = '/absolute/path/to/boot_dir'
# config.boot_files = lambda { ['/absolute/path/to/boot_dir/file.js'] }
#end
#
#Example: prevent PhantomJS auto install, uses PhantomJS already on your path.
#Jasmine.configure do |config|
# config.prevent_phantom_js_auto_install = true
#end
#
26 changes: 26 additions & 0 deletions spec/javascripts/support/run.html.erb
@@ -0,0 +1,26 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Jasmine suite</title>
<link rel="shortcut icon" type="image/png" href="/__images__/jasmine_favicon.png">
<% css_files.each do |css_file| %>
<link rel="stylesheet" href="<%= css_file %>" type="text/css" media="screen"/>
<% end %>
<%#<script id="specs" type="application/json"><%= spec_files.to_json %></script>%>
<script id="specs" type="application/json">[
'views/form_view_spec.js'
]</script>
<% js_files.each do |js_file| %>
<script src="<%= js_file %>" type="text/javascript"></script>
<% end %>

</head>
<body>

<div id="jasmine_content"></div>

</body>
</html>

0 comments on commit d193b93

Please sign in to comment.