Personally, I wouldn’t write specs for that directly, but I might check that 
attributes are instantiated correctly e.g.:

it “defaults to a good value” do
  expect(test_framework.name).to eq “RSpec"
end

Or that changing a attributes value changes something else

it “changes a persons full name” do
  expect { person.first_name = “Jon” }.to change { person.full_name }.to “Jon 
Rowe"
end

If you really wanted to check it on it’s own you could just do:

it “has an attribute” do
  expect { person.name = “Jon” }.to change { person.name }.to “Jon"
end



Jon Rowe
---------------------------
m...@jonrowe.co.uk
jonrowe.co.uk


On Monday, 11 January 2016 at 01:41, Tom Hale wrote:

> I'm quite surprised that there's not much out there when I google 'rspec  
> attr_accessor'
>  
> The best I've found (not tried) is:
> https://gist.github.com/daronco/4133411#file-have_attr_accessor-rb
>  
> Or (only does attr_accessor):
> http://stackoverflow.com/questions/24434381/ruby-rspec-how-should-i-be-testing-attr-accessor
>  
> What's the DRY way to write specs for methods created with  
> attr_(accessor|writer|reader)?
>  
> (Note, this is not rails)
>  
> Cheers,
> Tom
>  
> --  
> You received this message because you are subscribed to the Google Groups 
> "Ruby or Rails Oceania" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to rails-oceania+unsubscr...@googlegroups.com 
> (mailto:rails-oceania+unsubscr...@googlegroups.com).
> To post to this group, send email to rails-oceania@googlegroups.com 
> (mailto:rails-oceania@googlegroups.com).
> Visit this group at https://groups.google.com/group/rails-oceania.
> For more options, visit https://groups.google.com/d/optout.
>  
>  


-- 
You received this message because you are subscribed to the Google Groups "Ruby 
or Rails Oceania" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rails-oceania+unsubscr...@googlegroups.com.
To post to this group, send email to rails-oceania@googlegroups.com.
Visit this group at https://groups.google.com/group/rails-oceania.
For more options, visit https://groups.google.com/d/optout.

Reply via email to