This repository has been archived by the owner on Sep 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jasmine 2.0 support and junit formatter for legacy version , also upd…
…ated reporters to add more info and also the console output to ressemble more with Rspec
- Loading branch information
1 parent
d0036f9
commit c0f1081
Showing
17 changed files
with
758 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,52 @@ | ||
require "bundler/gem_tasks" | ||
require 'bundler/setup' | ||
require 'bundler/gem_tasks' | ||
require 'appraisal' | ||
require 'rspec/core/rake_task' | ||
require 'coveralls/rake/task' | ||
require 'yard' | ||
Coveralls::RakeTask.new | ||
|
||
RSpec::Core::RakeTask.new(:spec) do |spec| | ||
default_options = ['--colour'] | ||
default_options.concat(['--backtrace', '--fail-fast']) if ENV['DEBUG'] | ||
spec.rspec_opts = default_options | ||
spec.verbose = true | ||
end | ||
|
||
YARD::Config.options[:load_plugins] = true | ||
YARD::Config.load_plugins | ||
|
||
# dirty hack for YardocTask | ||
::Rake.application.class.class_eval do | ||
alias_method :last_comment, :last_description | ||
end | ||
|
||
YARD::Rake::YardocTask.new do |t| | ||
t.files = ['lib/**/*.rb', 'spec/**/*_spec.rb'] # optional | ||
t.options = ['--any', '--extra', '--opts', '--markup-provider=redcarpet', '--markup=markdown', '--debug'] # optional | ||
t.stats_options = ['--list-undoc'] # optional | ||
end | ||
|
||
desc 'Default: run the unit tests.' | ||
task default: [:all] | ||
|
||
desc 'Test the plugin under all supported Rails versions.' | ||
task :all do |_t| | ||
if ENV['TRAVIS'] | ||
# require 'json' | ||
# puts JSON.pretty_generate(ENV.to_hash) | ||
if ENV['BUNDLE_GEMFILE'] =~ /gemfiles/ | ||
appraisal_name = ENV['BUNDLE_GEMFILE'].scan(/rails\_(.*)\.gemfile/).flatten.first | ||
command_prefix = "appraisal rails-#{appraisal_name}" | ||
exec("#{command_prefix} bundle install && #{command_prefix} bundle exec rspec && bundle exec rake coveralls:push ") | ||
else | ||
exec(' bundle exec appraisal install && bundle exec rake appraisal spec && bundle exec rake coveralls:push') | ||
end | ||
else | ||
exec('bundle exec appraisal install && bundle exec rake appraisal spec') | ||
end | ||
end | ||
|
||
task :docs do | ||
exec('bundle exec inch --pedantic && bundle exec yard --list-undoc') | ||
end |
62 changes: 62 additions & 0 deletions
62
app/assets/javascripts/jasminerice_legacy_reporter.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#= require ./jasminerice_runner_base | ||
class JasminericeLegacyReporter extends window.JasminericeRunnerBase | ||
constructor : -> | ||
super | ||
|
||
reportRunnerStarting: (runner) -> | ||
super(runner) | ||
|
||
reportRunnerResults: (runner) -> | ||
@finished = true | ||
|
||
reportSpecResults: (spec) -> | ||
spec_result = if spec.results().failedCount > 0 then "failed" else "passed" | ||
spec_id = spec.id | ||
@totalCount++ | ||
@results_[spec_id] = { | ||
'status': spec_result | ||
'messages': spec.results().getItems(), | ||
'id': spec_id, | ||
'description': spec.description, | ||
'suite': spec.suite, | ||
'full_name': spec.getFullName() | ||
} | ||
@final_results_[spec_id] = @.summarizeResult_(spec, @results_[spec_id]) | ||
if spec_result == 'failed' | ||
@failedCount++ | ||
@failedSpecs.push(@final_results_[spec_id]) | ||
|
||
resultsForSpecs : (specIds) -> | ||
results = {} | ||
for i in [0...specIds.length] | ||
specId = specIds[i] | ||
results[specId] = @.summarizeResult_(specIds[i], @results_[specId]) | ||
results | ||
|
||
summarizeResult_ : (spec, result) -> | ||
summaryMessages = [] | ||
for messageIndex in [0...result.messages.length] | ||
resultMessage = result.messages[messageIndex] | ||
summaryMessages.push({ | ||
'status': if resultMessage.passed then resultMessage.passed() else true, | ||
'message': resultMessage.message, | ||
'matcherName': resultMessage.matcherName, | ||
'expected': ''+resultMessage.expected, | ||
'actual': ''+resultMessage.actual, | ||
'trace': { | ||
'stack': if resultMessage.passed && !resultMessage.passed() then resultMessage.trace.stack else jasmine.undefined | ||
} | ||
}) | ||
{ | ||
'id': result.id, | ||
'status': result.status | ||
'name': result.full_name, | ||
'description': result.description | ||
'messages': summaryMessages, | ||
'suite_name': @.getFullDescOfSuite(result.suite), | ||
} | ||
|
||
# make sure this exists so we don't have timing issue | ||
# when capybara hits us before the onload function has run | ||
window.jasmineRiceReporter = new JasminericeLegacyReporter() | ||
window.jasmineRiceReporter.register() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#= require ./jasminerice_runner_base | ||
class JasminericeReporter extends window.JasminericeRunnerBase | ||
constructor : -> | ||
super | ||
@runner_results = [] | ||
|
||
jasmineStarted: (suiteInfo) -> | ||
@started = true | ||
@failedSpecs = [] | ||
@totalCount = 0 | ||
@failedCount = 0 | ||
#@.log('Running suite with ' + suiteInfo.totalSpecsDefined) | ||
|
||
suiteStarted: (result) -> | ||
@suites_[suite.id] = @.summarize_(result) | ||
#@.log('Suite started: ' + result.description + ' whose full description is: ' + result.fullName) | ||
|
||
specStarted: (result) -> | ||
#@.log('Spec started: ' + result.description + ' whose full description is: ' + result.fullName) | ||
|
||
specDone: (spec) -> | ||
spec_result = if spec.failedExpectations.length > 0 then "failed" else "passed" | ||
spec_id = spec.id | ||
@totalCount++ | ||
@results_[spec_id] = { | ||
'status': spec_result | ||
'messages': spec.failedExpectations, | ||
'id': spec_id, | ||
'description': spec.description, | ||
'full_name': spec.fullName | ||
} | ||
@final_results_[spec_id] = @.summarizeResult_(spec, @results_[spec_id]) | ||
if spec_result == 'failed' | ||
@failedCount++ | ||
@failedSpecs.push(@final_results_[spec_id]) | ||
|
||
summarizeResult_ : (spec, result) -> | ||
summaryMessages = [] | ||
for messageIndex in [0...result.messages.length] | ||
resultMessage = result.messages[messageIndex] | ||
summaryMessages.push({ | ||
'status': result.status, | ||
'message': resultMessage.message, | ||
'matcherName': resultMessage.matcherName, | ||
'expected': ''+resultMessage.expected, | ||
'actual': ''+resultMessage.actual, | ||
'trace': { | ||
'stack': if !resultMessage.passed then resultMessage.stack else jasmine.undefined | ||
} | ||
}) | ||
{ | ||
'id': result.id, | ||
'status': result.status | ||
'name': result.full_name, | ||
'description': result.description | ||
'messages': summaryMessages, | ||
} | ||
|
||
suiteDone: (result) -> | ||
#The result here is the same object as in suiteStarted but with the addition of a status and a list of failedExpectations. | ||
@.log('Suite: ' + result.description + ' was ' + result.status); | ||
|
||
jasmineDone: -> | ||
@finished = true | ||
|
||
# make sure this exists so we don't have timing issue | ||
# when capybara hits us before the onload function has run | ||
window.jasmineRiceReporter = new JasminericeReporter() | ||
window.jasmineRiceReporter.register() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
class JasminericeRunnerBase | ||
constructor: -> | ||
@started = false | ||
@finished = false | ||
@failedSpecs = [] | ||
@totalCount = 0 | ||
@failedCount = 0 | ||
@failure_message = 'Failure/Error: ' | ||
# additional data ( optional ) | ||
@suites_ = {} | ||
@results_ = {} | ||
@final_results_ = {} | ||
|
||
results: -> | ||
@results_ | ||
|
||
all_summarized_results: -> | ||
summarized_results = [] | ||
for key, value of @final_results_ | ||
summarized_results.push(value) | ||
summarized_results | ||
|
||
suites: -> | ||
@suites_ | ||
|
||
extend_object: (object, properties) -> | ||
for key, val of properties | ||
object[key] = val | ||
object | ||
|
||
resultsForSpec: (specId) -> | ||
@results_[specId] | ||
|
||
getFullDescOfSuite: (suite) -> | ||
desc = "" | ||
while(suite.parentSuite) | ||
desc = suite.description + " " + desc | ||
suite = suite.parentSuite | ||
desc = suite.description + " " + desc | ||
desc | ||
|
||
reportRunnerStarting: (runner) -> | ||
@started = true | ||
suites = runner.topLevelSuites() | ||
for i in [0...suites.length] | ||
suite = suites[i] | ||
@suites_[suite.id] = @.summarize_(suite) | ||
|
||
summarize_ : (suiteOrSpec) -> | ||
isSuite = suiteOrSpec instanceof jasmine.Suite | ||
summary = { | ||
id: suiteOrSpec.id, | ||
name: suiteOrSpec.description, | ||
type: if isSuite then 'suite' else 'spec', | ||
children: [] | ||
} | ||
if (isSuite && suiteOrSpec.hasOwnProperty('children')) | ||
children = suiteOrSpec.children() | ||
for i in [0...children.length] | ||
summary.children.push(@.summarize_(children[i])) | ||
summary | ||
|
||
inspect: -> | ||
{ | ||
'started': @started, | ||
'finished': @finished, | ||
'totalCount': @totalCount, | ||
'failedCount': @failedCount | ||
'failedSpecs': @failedSpecs | ||
} | ||
|
||
log: (str) -> | ||
console.log(str) | ||
|
||
bindEvent: (eventHandler) -> | ||
eventName = 'DOMContentLoaded' | ||
if (document.addEventListener) | ||
document.addEventListener(eventName, eventHandler, false) | ||
else if (document.attachEvent) | ||
document.attachEvent('on'+eventName, eventHandler) | ||
|
||
register: -> | ||
@.bindEvent( => | ||
@.registerIntoJasmine() | ||
) | ||
|
||
registerIntoJasmine: -> | ||
jasmine.getEnv().addReporter(window.jasmineRiceReporter) | ||
|
||
window.JasminericeRunnerBase = JasminericeRunnerBase |
Oops, something went wrong.