Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #62 from redbooth/feature/cleanUpSpeedUpTests
Browse files Browse the repository at this point in the history
Cleaning up SpeedUp PR
  • Loading branch information
polqf committed Jan 12, 2016
2 parents 26a4b38 + 67dc35c commit 4738217
Showing 1 changed file with 42 additions and 16 deletions.
58 changes: 42 additions & 16 deletions Example/RealmResultsController-iOSTests/RealmSectionSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,12 @@ class SectionSpec: QuickSpec {
}

describe("insert(object:)") {
afterEach {
section.objects.removeAllObjects()
}

context("when the section is empty") {
it("beforeAll") {
beforeEach {
section = Section<Task>(keyPath: "keyPath", sortDescriptors: sortDescriptors)
section.insert(openTask)
}
Expand All @@ -151,35 +155,57 @@ class SectionSpec: QuickSpec {
}

context("when the section is not empty") {
it("beforeAll") {
beforeEach {
section.objects = [openTask]
section.insert(resolvedTask)
}
it("has two items") {
expect(section.objects.count).to(equal(2))
}
it("item is latest") {
it("lastObject is resolvedTask") {
expect(section.objects.lastObject === resolvedTask).to(beTrue())
}
}
}

describe("sort()") {
context("when the section is not empty") {
it("beforeAll") {
section = Section<Task>(keyPath: "keyPath", sortDescriptors: sortDescriptors)
section.insert(openTask)
section.insert(resolvedTask)
afterEach {
section.objects.removeAllObjects()
}

context("when the section is not empty and we add items unsorted") {
let aTask = Task()
aTask.id = 1502
aTask.name = "aaaaa"

let bTask = Task()
bTask.id = 1503
bTask.name = "bbbbb"

var aTaskIndex: Int!
var bTaskIndex: Int!
beforeEach {
let ascendingSortDescriptors = [NSSortDescriptor(key: "name", ascending: true)]
section = Section<Task>(keyPath: "keyPath", sortDescriptors: ascendingSortDescriptors)
//ADDING Tasks unsorted
section.insert(bTask)
section.insert(aTask)
aTaskIndex = section.objects.indexOfObject(aTask)
bTaskIndex = section.objects.indexOfObject(bTask)
section.sort()
}
it("before items have been sorted") {
expect(section.objects.firstObject === openTask).to(beTrue())
expect(section.objects.lastObject === resolvedTask).to(beTrue())

it("the aTask should not be in the same index as before") {
expect(section.objects.indexOfObject(aTask)) != aTaskIndex
}
it("sort items") {
section.sort()
it("the aTask index should be 0") {
expect(section.objects.indexOfObject(aTask)) == 0
}
it("after items have been sorted") {
expect(section.objects.firstObject === resolvedTask).to(beTrue())
expect(section.objects.lastObject === openTask).to(beTrue())
it("the bTask should not be in the same index as before") {
expect(section.objects.indexOfObject(bTask)) != bTaskIndex
}
it("the bTask index should be 1") {
expect(section.objects.indexOfObject(bTask)) == 1
}
}
}
Expand Down

0 comments on commit 4738217

Please sign in to comment.