forked from AdaGold/solar-system
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathsolar_system_spec.rb
More file actions
65 lines (56 loc) · 2.18 KB
/
solar_system_spec.rb
File metadata and controls
65 lines (56 loc) · 2.18 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
require "minitest/autorun"
require "minitest/reporters"
require_relative "../lib/solar_system"
# Get that nice colorized output
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
describe "solar_system" do
describe "initialize method" do
new_sol = SolarSystem.new("New Sol")
it "will create an instance of the class SolarSystem with an empty array planets " do
expect(new_sol).must_be_instance_of SolarSystem
expect(new_sol.planets).must_equal []
end
it "will read the star name when initialized" do
expect(new_sol.star_name).must_equal "New Sol"
end
end
describe "add_planet method" do
new_sol = SolarSystem.new("New Sol")
it "will take a planet and return an array of planets" do
pluto = Planet.new("Pluto", "pink", 56, 87, "pet-friendly")
expect(new_sol.add_planet(pluto)).must_be_instance_of Array
end
it "will take the parameter as a planet" do
pluto = "Pluto"
# note to me: when using curly braces, the code inside runs before expect
# when using with .must_raise
expect { new_sol.add_planet(pluto) }.must_raise ArgumentError
end
end
describe "list_planets method" do
new_sol = SolarSystem.new("New Sol")
pluto = Planet.new("Pluto", "pink", 56, 87, "pet-friendly")
new_sol.add_planet(pluto)
it "will return true if the list is an instance of a string" do
expect(new_sol.list_planets).must_be_instance_of String
end
end
describe "find_planet_by_name method" do
new_sol = SolarSystem.new("New Sol")
pluto = Planet.new("Pluto", "pink", 56, 87, "pet-friendly")
new_sol.add_planet(pluto)
it "will return an instance of Planet" do
expect(new_sol.find_planet_by_name("Pluto")).must_be_instance_of Planet
end
end
describe "distance_between method" do
it "will return the distance between two planets" do
new_sol = SolarSystem.new("New_Sol")
pluto = Planet.new("Pluto", "pink", 56, 87, "pet-friendly")
puffer = Planet.new("Puffer", "yellow", 78, 89, "not a planet")
new_sol.add_planet(pluto)
new_sol.add_planet(puffer)
expect(new_sol.distance_between(pluto.name, puffer.name)).must_equal 2
end
end
end