Repository navigation
Expand file tree
/
Copy pathtrainer_spec.rb
More file actions
74 lines (59 loc) · 2.39 KB
/
Copy pathtrainer_spec.rb
File metadata and controls
74 lines (59 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require 'simplecov'
require 'rspec'
SimpleCov.start
require './trainer.rb'
describe "it can load a deck and manuever through it" do
before :each do
File.stub!(:readlines).and_return(["term1\tdefinition1","term2\tdefinition2","term3\tdefinition3"])
@trainer = FlashcardApp::Trainer.new('filename.txt')
end
it "should know its position currently in the deck" do
@trainer.location.should eq 0
end
it "should move to the next card after a correct guess" do
@trainer.guess("incorrect_term")
@trainer.guess("term1")
@trainer.location.should eq 1
end
it "should move to the next card after 3 incorrect guesses" do
3.times {@trainer.guess("incorrect_term")}
@trainer.location.should eq 1
end
it "should return a hash containing the proper response for a false answer" do
@trainer.guess('incorrect_term').should eq ({:response => false})
end
it "should return a hash containing the proper response for a correct answer" do
@trainer.guess('term1').should eq ({:response => true, :definition => "definition2"})
end
it "should return a hash containing the proper response for 3 incorrect guesses" do
2.times {@trainer.guess("incorrect_term")}
@trainer.guess('incorrect_term').should eq ({:response => false, :definition => "definition2"})
end
it "can return a message to the UI when the deck has run out of cards" do
8.times {@trainer.guess("incorrect_term")}
@trainer.guess('incoreect_term')[:out_of_cards].should eq true
end
it "can does not return a message to the UI when the deck has NOT run out of cards" do
7.times {@trainer.guess("incorrect_term")}
@trainer.guess('incoreect_term')[:out_of_cards].nil?.should be true
end
it "should include a way to return the first word definition directly" do
@trainer.first_definition.should eq "definition1"
end
it "should return false for out_of_cards? when the deck still has cards" do
@trainer.guess('term1')
@trainer.out_of_cards?.should eq false
end
it "should return true for out_of_cards? method" do
@trainer.guess('term1')
@trainer.guess('term2')
@trainer.guess('term3')
@trainer.out_of_cards?.should eq true
end
it "can limit the number of cards played in a single session" do
@trainer = FlashcardApp::Trainer.new('filename.txt', 2)
@trainer.guess('term1')
@trainer.guess('term2')
@trainer.out_of_cards?.should eq true
end
end