How to detect an attribute rename from a view spec?

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.

The details:

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
include ResourcesHelper

before(:each) do
resource_98 = mock_model(Resource)
resource_98.should_receive(:entity).and_return(“MyString”)

end

it “should render list of resources” do
render “/resources/index.html.erb”
response.should have_tag(“tr>td”, “MyString”, 2)

end
end

It also generated a fixture and model spec, which I tweaked as follows:

describe Resource do
fixtures :resources

it “should have an entity” do
resources(:one).entity.should == ‘MyString’
end
end

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.

Any ideas?

Thanks,

Ben

Ben T.
Senior Developer

Mobile: +61 (0) 405 496 053

a passion for excellence
www.shinetech.com http://www.shinetech.com/

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.

On Fri, Jul 4, 2008 at 10:23 AM, Ben T. [email protected]
wrote:

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.

You should have a look at stories. They provide the integration
testing you are after. Basically, they run through your site page by
page and look to see what is happening.

Alternatively, you can look to using real objects in your specs
instead of lots of stubs. There is a performance hit on your specs,
though for me it has not been a problem… yet :slight_smile:

Another option would be something like Selenium, which actually opens
every page of your website one by one.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs