27-01-2022
Meta Stuff
Today's Foci
Focus 1
- Bud forms - 1 hour, until 11am
- Measure - complete form 1?
- Form 1 completed! and done half of 2! better! Not best formatting in world, but hugely improved. Change to word doc or learn another tool if required at a later date
Focus 2
- Encapsulation and Inheritance stuff
- Try to get
Focus 3
- learn MuPDF
- Make notes on man MuPDF
Topic
First, make a secretdiary, and then remake it into 2 classes
- Use TDD
made the Gemfile with the source and gems 'rspec' and 'rubocop' in
ran bundle - appears to have installed without issue
firstly make the spec file, and add the tests
require './lib/secretdiary'
describe SecretDiary do
let(:diary) { SecretDiary.new }
it '#locked by default' do
expect{diary.add_entries}.to raise_error 'Diary locked'
end
it '#locked by default' do
expect{diary.get_entries}.to raise_error 'Diary locked'
end
end
then build the class
class SecretDiary
def initialize
@lock = true
end
def add_entries
return fail 'Diary locked' unless @lock == false
end
def get_entries
return fail 'Diary locked' unless @lock == false
end
end
completely messed that up - remembered the { braces } for the RSpec syntax
then forgot to actually raise the error.
remember fail is for the user, whilst raise is for the programmer/system
Next, add the unlock method so the user can unlock the diary
I'll also need to add the method for adding an entry - pushing to an array
and a method for getting the entries too - an array of that contains strings presumably
I'm adding an access_reader to the diary - you can see if a diary has a lock or not, and it makes everything simpler. There would be no security issue, since the diary will tell you its locked if access is attempted whilst locked?
./spec/secretdiary.rb
require './lib/secretdiary'
describe SecretDiary do
let(:diary) { SecretDiary.new }
it '#locked by default' do
expect{diary.add_entries}.to raise_error 'Diary locked'
end
it '#locked by default' do
expect{diary.get_entries}.to raise_error 'Diary locked'
end
it '#unlocks' do
diary.unlock
expect(diary.lock).to eq false
end
it '#wont unlock if unlocked' do
diary.unlock
expect{diary.unlock}.to raise_error 'Diary already unlocked'
end
end
./lib/secretdiary.rb
class SecretDiary
attr_reader :lock
def initialize
@lock = true
end
def add_entries
return fail 'Diary locked' unless @lock == false
end
def get_entries
return fail 'Diary locked' unless @lock == false
end
def unlock
return fail 'Diary already unlocked' unless @lock == true
@lock = false
end
end
During our pairing I worked with a particulatrly lovely HOOM'N, whom it was a pleasure to work with!
We took our time, and made steady, focused progress through one question - though I must admit, I found it far too easy to get distracted! I was unusually chatty - I think it's simply from a mix of tiredness, and a lack of goalsetting. I actually find this course sometimes prevents goal setting.
This promotes baby step progress ( a great thing! ) but at the expense of having an actual target.
I'm wondering how I can better be productive - definitely talking less; so I'll have to be aware of that. I think I can talk about tech all day, so it's honestly best just to not get me started.
I'm glad my analogies and step-throughs help, but sometimes I feel they might lead further into complexity than I would like. And I can be verbose. How do I reduce this?
Can I ask what another party hopes to achieve with the session?
Perhaps I can guage what attitude to take.
Methods Learned Today
RSpec - be_truthy and be_falsy