Ben Teese
2008-Jul-04 00:23 UTC
[rspec-users] 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 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. ............................................................................ ................................ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080704/a44b581e/attachment.html>
Mikel Lindsaar
2008-Jul-04 01:15 UTC
[rspec-users] How to detect an attribute rename from a view spec?
On Fri, Jul 4, 2008 at 10:23 AM, Ben Teese <ben.teese at shinetech.com> 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 :) Another option would be something like Selenium, which actually opens every page of your website one by one. -- http://lindsaar.net/ Rails, RSpec, Puppet and Life blog....