Skip to content

Commit

Permalink
adding initial tests
Browse files Browse the repository at this point in the history
adding support for minitest

removing console logs
  • Loading branch information
roychoo committed Apr 20, 2015
1 parent 80b5c53 commit 085b027
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 6 deletions.
9 changes: 9 additions & 0 deletions lib/ruby-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ RubyTestView = require './ruby-test-view'

module.exports =
config:
minitestAllCommand:
type: 'string'
default: "ruby -I test test"
minitestFileCommand:
type: 'string'
default: "ruby -I test {relative_path}"
minitestSingleCommand:
type: 'string'
default: "ruby {relative_path} -n \"/{regex}/\""
testAllCommand:
type: 'string'
default: "ruby -I test test"
Expand Down
25 changes: 24 additions & 1 deletion lib/source-info.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports =
test: 'test'
spec: 'rspec'
feature: 'cucumber'
minitest: 'minitest'

currentShell: ->
atom.config.get('ruby-test.shell') || 'bash'
Expand Down Expand Up @@ -37,6 +38,25 @@ module.exports =
else
null

minitestRegExp: (text)->
@_minitestRegExp ||= unless @_minitestRegExp
value = []
value = text.match(/"(.*?)"/) if text?
value[1] || ""

isMiniTest: ->
editor = atom.workspace.getActiveTextEditor()
cursor = editor and editor.getCursor()
i = cursor.getBufferRow()
regExp = new RegExp(/^(\s+)(should|test|it)\s+['""'](.*)['""']\s+do\s*(?:#.*)?$/)
while i > 0
text = editor.lineTextForBufferRow(i)
if regExp.test(text)
@minitestRegExp(text)
return true
i--
return false

testFramework: ->
@_testFramework ||= unless @_testFramework
(t = @fileType()) and @frameworkLookup[t] or
Expand All @@ -47,7 +67,10 @@ module.exports =
if not @activeFile()
null
else if matches = @activeFile().match(/_(test|spec)\.rb$/)
matches[1]
if @isMiniTest()
"minitest"
else
matches[1]
else if matches = @activeFile().match(/\.(feature)$/)
matches[1]

Expand Down
3 changes: 2 additions & 1 deletion lib/test-runner.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ module.exports =
else
@testParams.testFileCommand()
cmd.replace('{relative_path}', @testParams.activeFile()).
replace('{line_number}', @testParams.currentLine())
replace('{line_number}', @testParams.currentLine()).
replace('{regex}', @testParams.minitestRegExp())

cancel: ->
@shell.kill()
34 changes: 30 additions & 4 deletions spec/source-info-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,28 @@ describe "SourceInfo", ->
atom.config.set("ruby-test.#{framework}SingleCommand", "foo-#{framework}SingleCommand")


setUpOpenFile = ->
editor = {buffer: {file: {path: "foo_test.rb"}}}
setUpOpenFile = (text="")->
editor =
{
buffer: {
file: {
path: "foo_test.rb"
}
},
getCursor: ->
{
getBufferRow: ->
return 1
}
lineTextForBufferRow: (line)->
return text
}
spyOn(atom.workspace, 'getActiveTextEditor').andReturn(editor)

setUpWithOpenFile = ->
setUpWithOpenFile = (text="") ->
setUpProjectPaths()
setUpPackageConfig()
setUpOpenFile()
setUpOpenFile(text)
sourceInfo = new SourceInfo()

setUpWithoutOpenFile = ->
Expand All @@ -52,6 +66,11 @@ describe "SourceInfo", ->
setUpWithoutOpenFile()
expect(sourceInfo.cwd()).toBe("fooPath")

describe "::fileType", ->
it "correctly detects a minitest file", ->
setUpWithOpenFile(" it \"test something\" do")
expect(sourceInfo.fileType()).toBe("minitest")

describe "::projectType", ->
it "correctly detects a test directory", ->
spyOn(fs, 'existsSync').andCallFake (filePath) ->
Expand All @@ -60,6 +79,13 @@ describe "SourceInfo", ->
setUpWithoutOpenFile()
expect(sourceInfo.projectType()).toBe("test")

it "correctly detects a minitest directory", ->
spyOn(fs, 'existsSync').andCallFake (filePath) ->
filePath.match(/fooPath\/test$/)

setUpWithoutOpenFile("it \"test something\"")
expect(sourceInfo.projectType()).toBe("test")

it "correctly detecs a spec directory", ->
spyOn(fs, 'existsSync').andCallFake (filePath) ->
filePath.match(/fooPath\/spec$/)
Expand Down

0 comments on commit 085b027

Please sign in to comment.