[rspec-users] How it would be tested?

Costa Shapiro costa at mouldwarp.com
Wed Jul 21 16:24:01 EDT 2010


Dear Mr. Learner,

Please note that while very similar in functionality, specs' philosophy
differs from tests' (especially from non-TDD ones).
That is, you write spec first, see it fail, and write some code to make it
pass.
If you happen to write any implementation code first, you should disregard
it while writing a spec.
You may find BDD reading in abundance on the internets.

To get a more substantial reply, I think you might want to describe what you
want your code to do in plain English, and the community will hopefully help
you to express that in rspec.

Cheers,
Costa.

On 12 July 2010 13:35, tests learner <tests.learner at gmail.com> wrote:

> Hello all.
>
> I'm working with rails and came to a situation that i cannot imagine
> how to test this.
>
> Given i have an index action that retrieves me a collection of
> objects.
> But some of them have especific permissions.
>
>
> My index action act like this:
> - retrieve public objects.
> - retrieve permission 1 objects.
> - retrieve permission 2 objects.
>
> So i have to write 3 tests.
>
> it "should retrieve public objects"
>
> context "permission 1"
>  it " should retrieve permission 1 objects"
> context "permission 2"
>  it "should retrieve permission 2 objects"
>
>
> Until here no problems because only conditional tests and method
> calls.
>
> But how i would test the "Index.retrieve_objects_from_permission1" ?
>
> supose i have
>
> class  Index < ActiveRecord::Base
>   has_many :permissions
>   def self.retrieve_objects_from_permission1
>       Index.all(:conditions => "permissions.id = 1", :include
> => :permissions)
>   end
>
>    def has_permission1
>       !self.permissions.find_by_id(1).nil?
>    end
> end
>
>
> My Index.retrieve_objects_from_permission1 would be:
>
> it "should retrieve objects that have permission 1" do
>   @collection = Index.retrieve_objects_from_permission1
>   @collection.each do |c|
>       c.has_permission1.should == true
>    end
> end
>
> Is it right? ( I didn't see it before on other's code, so i don't
> think it's right.)
>
>
> Sorry for my poor english. i hope I have been clear enough.
>
>
> Thank you :)
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100721/56b8198f/attachment.html>


More information about the rspec-users mailing list