Skip to content

Commit

Permalink
Refactoring to add runLast command that re-runs last spec
Browse files Browse the repository at this point in the history
  • Loading branch information
fcoury committed Mar 1, 2014
1 parent 70fbd2a commit 9f165cd
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 33 deletions.
3 changes: 2 additions & 1 deletion keymaps/rspec.cson
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
# https://atom.io/docs/latest/advanced/keymaps
'.editor':
'ctrl+alt+t': 'rspec:run'
'ctrl+alt+r': 'rspec:runForLine'
'ctrl+alt+x': 'rspec:run-for-line'
'ctrl+alt+e': 'rspec:run-last'
20 changes: 10 additions & 10 deletions lib/rspec-output-view.coffee → lib/rspec-view.coffee
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{$, $$$, EditorView, ScrollView, View} = require 'atom'
{$, $$$, EditorView, ScrollView} = require 'atom'
ChildProcess = require 'child_process'
path = require 'path'

module.exports =
class RSpecOutputView extends ScrollView
class RSpecView extends ScrollView
atom.deserializers.add(this)

@deserialize: ({filePath}) ->
new RSpecOutputView(filePath)
new RSpecView(filePath)

@content: ->
@div class: 'rspec-output', tabindex: -1, =>
@div class: 'rspec', tabindex: -1, =>
@div class: 'rspec-spinner', 'Starting RSpec...'
@pre class: 'rspec-terminal'
@pre class: 'rspec-output'

constructor: (filePath) ->
super
console.log "File path:", filePath
@filePath = filePath

@output = @find(".rspec-output")
@terminal = @find(".rspec-terminal")
@spinner = @find(".rspec-spinner")
@terminal.on("click", @terminalClicked)
@output.on("click", @terminalClicked)

serialize: ->
deserializer: 'RSpecOutputView'
deserializer: 'RSpecView'
filePath: @getPath()

destroy: ->
Expand Down Expand Up @@ -56,7 +56,7 @@ class RSpecOutputView extends ScrollView

run: (line_number) ->
@spinner.show()
@terminal.empty()
@output.empty()
project_path = atom.project.getRootDirectory().getPath()

spawn = ChildProcess.spawn
Expand Down Expand Up @@ -85,7 +85,7 @@ class RSpecOutputView extends ScrollView
"<a href='#{file}' data-line='#{line}'>#{match}</a>"

@spinner.hide()
@terminal.append("#{output}")
@output.append("#{output}")
@scrollTop(@[0].scrollHeight)

onStdOut: (data) =>
Expand Down
37 changes: 23 additions & 14 deletions lib/rspec.coffee
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
url = require 'url'

RSpecOutputView = require './rspec-output-view'
RSpecView = require './rspec-view'

module.exports =
activate: ->
console.log "Activating"
atom.workspaceView.command 'rspec:runForLine', =>
console.log "Trying to runForLine..."
@runForLine()
activate: (state) ->
if state?
@lastFile = state.lastFile
@lastLine = state.lastLine

console.log "Activating 2"
atom.workspaceView.command 'rspec:run', =>
@run()
atom.workspaceView.command 'rspec:run' , => @run()
atom.workspaceView.command 'rspec:run-for-line', => @runForLine()
atom.workspaceView.command 'rspec:run-last' , => @runLast()

console.log "Activating 3"
atom.workspace.registerOpener (uriToOpen) ->
{protocol, pathname} = url.parse(uriToOpen)
return unless protocol is 'rspec-output:'
new RSpecOutputView(pathname)
new RSpecView(pathname)

rspecView: null

Expand All @@ -26,13 +24,18 @@ module.exports =

serialize: ->
rspecViewState: @rspecView.serialize()
lastFile: @lastFile
lastLine: @lastLine

openUriFor: (file, line_number) ->
@lastFile = file
@lastLine = line_number

previousActivePane = atom.workspace.getActivePane()
uri = "rspec-output://#{file}"
atom.workspace.open(uri, split: 'right', changeFocus: false, searchAllPanes: true).done (rspecOutputView) ->
if rspecOutputView instanceof RSpecOutputView
rspecOutputView.run(line_number)
atom.workspace.open(uri, split: 'right', changeFocus: false, searchAllPanes: true).done (rspecView) ->
if rspecView instanceof RSpecView
rspecView.run(line_number)
previousActivePane.activate()

runForLine: ->
Expand All @@ -45,9 +48,15 @@ module.exports =
console.log "Cursor", cursor
line = cursor.getScreenRow()
console.log "Line", line

@openUriFor(editor.getPath(), line)

runLast: ->
return unless @lastFile?
@openUriFor(@lastFile, @lastLine)

run: ->
console.log "RUN"
editor = atom.workspace.getActiveEditor()
return unless editor?

Expand Down
8 changes: 5 additions & 3 deletions menus/rspec.cson
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
'context-menu':
'.overlayer':
'Run All Specs': 'rspec:run'
'Run Current Spec': 'rspec:runForLine'
'Run Current Spec': 'rspec:run-for-line'
'Re-Run Last Spec': 'rspec:run-last'

'menu': [
{
'label': 'Packages'
'submenu': [
'label': 'RSpec'
'submenu': [
{ 'label': 'Run all specs', 'command': 'rspec:run' }
{ 'label': 'Run current spec', 'command': 'rspec:runForLine' }
{ 'label': 'Run All Specs', 'command': 'rspec:run' }
{ 'label': 'Run Current Spec', 'command': 'rspec:run-for-line' }
{ 'label': 'Re-Run Last Spec', 'command': 'rspec:run-last' }
]
]
}
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "rspec",
"main": "./lib/rspec",
"version": "1.1.0",
"version": "0.0.0",
"private": true,
"description": "Atom RSpec runner package",
"activationEvents": [
"rspec:run",
"rspec:runForFile"
"rspec:run-for-line",
"rspec:run-last"
],
"repository": "https://github.com/fcoury/atom-rspec",
"license": "MIT",
Expand Down
6 changes: 3 additions & 3 deletions stylesheets/rspec.less
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
text-align: center;
}

.rspec-output {
.rspec {
background-color: black;
color: white;
overflow: scroll;
}

.rspec-output {
.rspec {
pre,
pre div.editor,
code,
Expand All @@ -34,7 +34,7 @@
color: #0099cc;
}

.rspec-terminal {
.rspec-output {
background: #000;
color: #fff;
}
Expand Down

0 comments on commit 9f165cd

Please sign in to comment.