[rspec-users] How to detect an attribute rename from a view spec?
ben.teese at shinetech.com
Thu Jul 3 20:23:57 EDT 2008
I'm new to RSpec so excuse me if I'm missing something obvious here. I
recently renamed an attribute on a model, and my generated view spec didn't
detect it. This resulted in a defect going through undetected. Even worse,
I'm not sure how I could reasonably get RSpec to detect such a change.
I suspect the problem isn't specific to RSpec, but I encountered it whilst
dealing with RSpec and thought this would be a good place to ask for advice.
I used RSpec to generate scaffolding for a model we'll call 'Resource'.
Resource has an attribute called 'entity'.
It generated for me a view for a Resource - including its 'entity'
attribute. It also generated a corresponding spec that looked like this:
describe "/resources/index.html.erb" do
resource_98 = mock_model(Resource)
it "should render list of resources" do
response.should have_tag("tr>td", "MyString", 2)
It also generated a fixture and model spec, which I tweaked as follows:
describe Resource do
it "should have an entity" do
resources(:one).entity.should == 'MyString'
Both specs pass. Excuse the lame model spec - I'm about to get to the point.
Next I decided I wanted to rename the 'entity' attribute to 'entities'. My
model spec failed, so I fixed it. However, the view spec didn't fail. It
expected that the view would call 'entity' on the mock Resource - and this
was indeed still the case.
However, when I went and actually looked at the page, it died - the 'entity'
attribute didn't exist anymore on the model.
I'm not sure how I could have picked that up with an automated test.
Mobile: +61 (0) 405 496 053
a passion for excellence
This email is intended solely for the use of the addressee
and may contain information that is confidential or privileged.
If you receive this email in error please notify the sender and
delete the email immediately.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the rspec-users