more cleanup, start tests

This commit is contained in:
John Bintz 2012-01-16 14:58:05 -05:00
parent e4b2d39b31
commit 98982e28e5
7 changed files with 94 additions and 32 deletions

1
.gitignore vendored
View File

@ -15,3 +15,4 @@ spec/reports
test/tmp
test/version_tmp
tmp
.jhw-cache/

View File

@ -2,3 +2,8 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in jasmine-gwt.gemspec
gemspec
gem 'guard', '~> 0.8.0'
gem 'jasmine-headless-webkit', :path => '../jasmine-headless-webkit'
gem 'guard-jasmine-headless-webkit', :path => '../guard-jasmine-headless-webkit'
gem 'rb-fsevent'

16
Guardfile Normal file
View File

@ -0,0 +1,16 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
# Run JS and CoffeeScript files in a typical Rails 3.1/Sprockets fashion.
# Your spec files end with _spec.{js,coffee}.
spec_location = "spec/javascripts/%s_spec"
# uncomment if you use NerdCapsSpec.js
# spec_location = "spec/javascripts/%sSpec"
guard 'jasmine-headless-webkit' do
watch(%r{^(app|lib|vendor)/assets/javascripts/(.*)\.js.coffee$}) { |m| newest_js_file(spec_location % m[1]) }
watch(%r{^spec/javascripts/(.*)[Ss]pec\..*}) { |m| newest_js_file(spec_location % m[1]) }
end

View File

@ -39,6 +39,40 @@ class jasmine.GWT.Scenario extends jasmine.GWT.Background
if isLast
jasmine.GWT.runHook('After', _this)
runFailure = (type, name, args) ->
it "#{type} #{name}", ->
output = [ "", "No step defined for #{type} #{name}. Define one using the following:", '' ]
argCount = args.length
name = name.replace /\d+/g, (match) ->
argCount += 1
"(\\d+)"
name = name.replace /\"[^"]+\"/g, (match) ->
argCount += 1
'"([^"]+)"'
if argCount == 0
output.push("#{type} /^#{name}$/, ->")
else
args = ("arg#{i}" for i in [ 1..(argCount) ])
output.push("#{type} /^#{name}$/, (#{args.join(', ')}) ->")
output.push(" @not_defined()")
output.push("")
this.addMatcherResult(
new jasmine.ExpectationResult(
matcherName: 'steps',
passed: false,
expected: 'to be defined',
actual: "#{type} #{name}",
message: output.join("\n")
)
)
args = []
if param?
@ -66,38 +100,7 @@ class jasmine.GWT.Scenario extends jasmine.GWT.Background
break
if !found
output = [ "", "No step defined for #{type} #{name}. Define one using the following:", '' ]
argCount = args.length
name = name.replace /\d+/g, (match) ->
argCount += 1
"(\\d+)"
name = name.replace /\"[^"]+\"/g, (match) ->
argCount += 1
'"([^"]+)"'
if argCount == 0
output.push("#{type} /#{name}/, ->")
else
args = ("arg#{i}" for i in [ 1..(argCount) ])
output.push("#{type} /#{name}/, (#{args.join(', ')}) ->")
output.push(" @not_defined()")
output.push("")
fakeResult = new jasmine.ExpectationResult(
matcherName: 'steps',
passed: false,
expected: 'to be defined',
actual: "#{type} #{name}",
message: output.join("\n")
)
jasmine.getEnv().currentSpec.addMatcherResult(fakeResult)
runFailure(type, name, args) if !found
allStatements: =>
allStatements = []

View File

@ -1,2 +1,30 @@
describe 'jasmine.GWT', ->
describe '.Step', ->
type = 'type'
name = 'name'
parameter = 'parameter'
beforeEach ->
jasmine.GWT.Steps = {}
context 'no running scenario', ->
beforeEach ->
jasmine.GWT.currentScenario_ = null
it 'should add the step to the available steps list', ->
jasmine.GWT.Step(type, name, parameter)
expect(jasmine.GWT.Steps[type]).toEqual([ [ name, parameter ] ])
context 'running scenario', ->
beforeEach ->
jasmine.GWT.currentScenario_ = {}
jasmine.GWT.currentScenario_[type] = ->
spyOn(jasmine.GWT.currentScenario_, type)
it 'should run the code in the scenario', ->
jasmine.GWT.Step(type, name, parameter)
expect(jasmine.GWT.currentScenario_[type]).toHaveBeenCalledWith(name, parameter)

View File

@ -0,0 +1,2 @@
window.context = window.describe

View File

@ -0,0 +1,7 @@
src_dir: lib/assets/javascripts
src_files: [ 'jasmine-gwt.js.coffee' ]
spec_dir: spec/javascripts
spec_files: [ '**/*_spec.coffee' ]
helpers: [ 'spec_helper.coffee' ]