Globally mock pasteboard read and write in specs

This commit is contained in:
Kevin Sawicki & Nathan Sobo
2013-01-10 10:56:55 -08:00
parent c3a2b99b69
commit 4dc7ade4e6
2 changed files with 7 additions and 6 deletions

View File

@@ -1358,11 +1358,7 @@ describe "EditSession", ->
expect(editSession.getCursorScreenPosition()).toEqual [0, editSession.getTabLength() * 2]
describe "pasteboard operations", ->
pasteboard = null
beforeEach ->
pasteboard = 'first'
spyOn($native, 'writeToPasteboard').andCallFake (text) -> pasteboard = text
spyOn($native, 'readFromPasteboard').andCallFake -> pasteboard
editSession.setSelectedBufferRanges([[[0, 4], [0, 13]], [[1, 6], [1, 10]]])
describe ".cutSelectedText()", ->
@@ -1381,7 +1377,7 @@ describe "EditSession", ->
editSession.cutToEndOfLine()
expect(buffer.lineForRow(2)).toBe ' if (items.length'
expect(buffer.lineForRow(3)).toBe ' var pivot = item'
expect(pasteboard).toBe ' <= 1) return items;\ns.shift(), current, left = [], right = [];'
expect(pasteboard.read()[0]).toBe ' <= 1) return items;\ns.shift(), current, left = [], right = [];'
describe "when text is selected", ->
it "only cuts the selected text, not to the end of the line", ->
@@ -1391,7 +1387,7 @@ describe "EditSession", ->
expect(buffer.lineForRow(2)).toBe ' if (items.lengthurn items;'
expect(buffer.lineForRow(3)).toBe ' var pivot = item'
expect(pasteboard).toBe ' <= 1) ret\ns.shift(), current, left = [], right = [];'
expect(pasteboard.read()[0]).toBe ' <= 1) ret\ns.shift(), current, left = [], right = [];'
describe ".copySelectedText()", ->
it "copies selected text onto the clipboard", ->
@@ -1402,6 +1398,7 @@ describe "EditSession", ->
describe ".pasteText()", ->
it "pastes text into the buffer", ->
pasteboard.write('first')
editSession.pasteText()
expect(editSession.buffer.lineForRow(0)).toBe "var first = function () {"
expect(buffer.lineForRow(1)).toBe " var first = function(items) {"

View File

@@ -47,6 +47,10 @@ beforeEach ->
TokenizedBuffer.prototype.chunkSize = Infinity
spyOn(TokenizedBuffer.prototype, "tokenizeInBackground").andCallFake -> @tokenizeNextChunk()
pasteboardContent = 'initial pasteboard content'
spyOn($native, 'writeToPasteboard').andCallFake (text) -> pasteboardContent = text
spyOn($native, 'readFromPasteboard').andCallFake -> pasteboardContent
afterEach ->
keymap.bindingSets = bindingSetsToRestore
keymap.bindingSetsByFirstKeystrokeToRestore = bindingSetsByFirstKeystrokeToRestore