Given an author a with first name 'Alan' and last name 'Turing'
Then a.name should be 'Alan Turing'
Hints
The author model should have a first_name, last_name and homepage, which are all strings.
It should furthermore have a method name (no parameters) which returns the full name of an author (the first name followed by the last name), e.g. 'Alan Turing'.
Test this model behavior in a model test. Create spec/models/author_spec.rb and in the describe block, specify type: :model.
In a model test, behavior is tested directly on the model object, e.g.
To pass your test a Rails model for authors must be created. Rails has generators which make creating things easier. You can answer 'no' when Rails asks if you want to overwrite files, then your edited files stay the way they are.
Here is the relevant section (5.4) of the Rails Guide. The generator creates the required model attributes (e.g. first_name:string, see db/schema.rb for the changes) and maps them to the corresponding model. You can then use the attributes as variables in the model (i.e. author.first_name).
Additional model methods are specified in the model's file, e.g. app/models/author.rb using standard Ruby syntax.
Error
Got NoMethodError: undefined method `name' for #
5 exercise tests have passed. There are 44 in total. You will solve multiple at once towards the end.
Scenario
Given an author
a
with first name 'Alan' and last name 'Turing' Thena.name
should be 'Alan Turing'Hints
The author model should have a
first_name
,last_name
andhomepage
, which are all strings. It should furthermore have a methodname
(no parameters) which returns the full name of an author (the first name followed by the last name), e.g. 'Alan Turing'.Test this model behavior in a model test. Create
spec/models/author_spec.rb
and in thedescribe
block, specifytype: :model
. In a model test, behavior is tested directly on the model object, e.g.The
eq
matcher tests for object equivalence. See this reference for more matchers.To pass your test a Rails model for authors must be created. Rails has
generators
which make creating things easier. You can answer 'no' when Rails asks if you want to overwrite files, then your edited files stay the way they are. Here is the relevant section (5.4) of the Rails Guide. The generator creates the required model attributes (e.g.first_name:string
, seedb/schema.rb
for the changes) and maps them to the corresponding model. You can then use the attributes as variables in the model (i.e.author.first_name
).Additional model methods are specified in the model's file, e.g.
app/models/author.rb
using standard Ruby syntax.Error
5 exercise tests have passed. There are 44 in total. You will solve multiple at once towards the end.