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 Teese
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.
............................................................................
................................

 

_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to