Skip to content

Commit

Permalink
first steps in rspec version
Browse files Browse the repository at this point in the history
  • Loading branch information
Bayonnaise committed Jun 30, 2014
1 parent 51a08d2 commit a617718
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 45 deletions.
Binary file modified .DS_Store
Binary file not shown.
30 changes: 0 additions & 30 deletions cohorts.csv

This file was deleted.

15 changes: 0 additions & 15 deletions cohorts1.csv

This file was deleted.

17 changes: 17 additions & 0 deletions lib/directory5.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def students
@students ||= []
end

def add(student)
students << student
end

def student_to_s(student)
"#{student[:name]}, #{student[:cohort]} cohort"
end

def students_to_s
students.map.with_index(1) do |student, index|
"#{index}.#{student_to_s(student)}"
end.join("\n")
end
72 changes: 72 additions & 0 deletions lib/directory5_sample.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
def add(student)
students << student
end

def students
@students ||= []
end

def student_to_s(student)
"#{student[:name]}, #{student[:cohort]} cohort"
end

def students_to_s
students.map.with_index(1) do |student, index|
"#{index}. #{student_to_s(student)}"
end.join("\n")
end

def print_students
show students_to_s
end

# def is_a_hash?
# true
# end

# def user_input
# gets.chomp
# end

def show(string)
puts string
end

def print_header
show "Welcome to the Makers Academy\nThe students of my cohort are..."
end

def print_footer(names)
show "Overall , we have #{names.length} superdooper students"
end

def print_array
show "test"
end

def request_name
show "Please enter the student's name"
request("name")
end

def request_cohort
show "Please enter the student's cohort"
request("cohort")
end

def request_hobby
show "Please enter the student's hobby"
request("hobby")
end

def request(thing)
thing = gets.chomp
end



# request(hobby)
# request(cohort)
# request()

# request_hobby
25 changes: 25 additions & 0 deletions spec/directory5_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'directory5'

describe 'student directory' do
it 'has no students' do
expect(students).to be_empty
end

it 'add a student' do
student = [{name: "David", cohort: "June"}]
add(student)
expect(students).to eq [student]
end

it 'give us a student line' do
student = {name: "David", cohort: "June"}
expect(student_to_s(student)).to eq "David, June cohort"
end

it 'gives us a whole bunch of student lines' do
["David", "chloe", "sam"].each do |name|
add({name: name, cohort: "June"})
end
expect(students_to_s).to eq "1.David, June cohort\n2.chloe, June cohort\n3.sam, June cohort"
end
end
89 changes: 89 additions & 0 deletions spec/directory5_spec_sample.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
require 'directory5'

describe 'student directory' do
it 'has no students' do
expect(students).to be_empty
end

it 'adds a student' do
student = { name: "David", cohort: "June" }
add(student)
expect(students).to eq [student]
end

it 'gives us a student line' do
student = { name: "David", cohort: "June" }
expect(student_to_s(student)).to eq 'David, June cohort'
end

it 'gives us a whole bunch of student lines' do
%w{David Chloe Zoe}.each do |name|
add({name: name, cohort: 'June'})
end

expect(students_to_s).to eq "1. David, June cohort\n2. Chloe, June cohort\n3. Zoe, June cohort"
end

it 'prints em' do
%w{David Chloe Zoe}.each do |name|
add({name: name, cohort: 'June'})
end
expect(self).to receive(:show).with("1. David, June cohort\n2. Chloe, June cohort\n3. Zoe, June cohort")

print_students
end

context 'informs about schtuff' do

it 'prints a string to the terminal' do
expect(self).to receive(:puts).with("HELLO!")
show("HELLO!")
end

it 'prints header' do
expect(self).to receive(:show).with("Welcome to the Makers Academy\nThe students of my cohort are...")
print_header
end

it 'prints footer' do
expect(self).to receive(:show)
print_footer(students)
end
end

context 'should prompt for' do
it 'name' do
input = "Chloe"
expect(self).to receive(:puts).with("Please enter the student's name")
expect(self).to receive(:gets).and_return(input)
expect(request_name).to eq "Chloe"
end

it 'cohort' do
input = "June"
expect(self).to receive(:puts).with("Please enter the student's cohort")
expect(self).to receive(:gets).and_return(input)
expect(request_cohort).to eq "June"
end

it 'hobby' do
input = "Being noisy"
expect(self).to receive(:puts).with("Please enter the student's hobby")
expect(self).to receive(:gets).and_return(input)
expect(request_hobby).to eq "Being noisy"
end

# it 'anything we want' do
# thing = hobby
# expect(self).to receive(:puts).with("Please enter the student's #{thing}")
# expect(self).to receive(:gets).and_return(thing)
# expect(request(thing)).to eq "hobby"
# end

end

# it 'prints each of the elements in a hash' do
# expect(self).to receive(:show)
# print_array
# end
end

0 comments on commit a617718

Please sign in to comment.