Class: JLDrill::StoryMemento

Inherits:
Object
  • Object
show all
Defined in:
lib/jldrill/spec/StoryMemento.rb

Overview

This is a helper class for the tests. It makes it easier to set up and tear down the test. It also keeps track of the state of the app.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(storyName) ⇒ StoryMemento

Returns a new instance of StoryMemento.



14
15
16
17
# File 'lib/jldrill/spec/StoryMemento.rb', line 14

def initialize(storyName)
    @storyName = storyName
    restart
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



11
12
13
# File 'lib/jldrill/spec/StoryMemento.rb', line 11

def app
  @app
end

#contextObject (readonly)

Returns the value of attribute context.



11
12
13
# File 'lib/jldrill/spec/StoryMemento.rb', line 11

def context
  @context
end

#mainContextObject (readonly)

Returns the value of attribute mainContext.



11
12
13
# File 'lib/jldrill/spec/StoryMemento.rb', line 11

def mainContext
  @mainContext
end

#mainViewObject (readonly)

Returns the value of attribute mainView.



11
12
13
# File 'lib/jldrill/spec/StoryMemento.rb', line 11

def mainView
  @mainView
end

#storyNameObject (readonly)

Returns the value of attribute storyName.



11
12
13
# File 'lib/jldrill/spec/StoryMemento.rb', line 11

def storyName
  @storyName
end

#viewObject (readonly)

Returns the value of attribute view.



11
12
13
# File 'lib/jldrill/spec/StoryMemento.rb', line 11

def view
  @view
end

Instance Method Details

#getNewViewObject

Create a new view after the old one has been destroyed



66
67
68
# File 'lib/jldrill/spec/StoryMemento.rb', line 66

def getNewView
    @view = @context.peekAtView
end

#restartObject



19
20
21
22
23
24
25
# File 'lib/jldrill/spec/StoryMemento.rb', line 19

def restart
    @app = nil
    @mainContext = nil
    @mainView = nil
    @context = nil
    @view = nil
end

#setup(type) ⇒ Object



31
32
33
34
35
# File 'lib/jldrill/spec/StoryMemento.rb', line 31

def setup(type)
    @app = JLDrill::Fakes::App.new(type, JLDrill::MainContext)
    @mainContext = @app.mainContext
    @mainView = @mainContext.peekAtView
end

#shutdownObject

This is very important to call when using setupGtk because otherwise you will leave windows hanging open.



60
61
62
63
# File 'lib/jldrill/spec/StoryMemento.rb', line 60

def shutdown
    @mainContext.exit
    restart
end

#startObject



54
55
56
# File 'lib/jldrill/spec/StoryMemento.rb', line 54

def start
    @app.enter
end

#stepName(step) ⇒ Object



27
28
29
# File 'lib/jldrill/spec/StoryMemento.rb', line 27

def stepName(step)
    @storyName + " - " + step
end

#useChineseTestDictionaryObject



45
46
47
48
49
50
51
52
# File 'lib/jldrill/spec/StoryMemento.rb', line 45

def useChineseTestDictionary
    @mainContext.quiz.options.language = "Chinese"
    # Override with the small test dictionary
    rc = @mainContext.loadReferenceContext
			def rc.dictionaryName(options)
				return File.join("tests", "cedict.utf")
			end
end

#useTestDictionaryObject



37
38
39
40
41
42
43
# File 'lib/jldrill/spec/StoryMemento.rb', line 37

def useTestDictionary
    # Override with the small test dictionary
    rc = @mainContext.loadReferenceContext
			def rc.dictionaryName(options)
				return File.join("tests", "edict.utf")
			end
end