[rspec-users] Getting Class in Shared Behaviours
Nathan Sutton
nathan.sutton at gmail.com
Wed Nov 21 16:39:40 EST 2007
Some of this clears up my issues around sharing behaviors that you can
pass parameters to. I was doing a hackish solution before by
including a module then calling a method it provides, but now I can
have shared behaviors and just have them call specific methods which
then become a convention to define. It still feels hackish, but not
nearly as much. Is there another way?
Nathan Sutton
fowlduck at gmail.com
rspec edge revision 2910
rspec_on_rails edge revision 2909
rails edge revision 8175
On Nov 21, 2007, at 3:31 PM, aslak hellesoy wrote:
> On Nov 21, 2007 10:22 PM, David Chelimsky <dchelimsky at gmail.com>
> wrote:
>>
>> On Nov 21, 2007 3:14 PM, Daniel N <has.sox at gmail.com> wrote:
>>> Hi,
>>>
>>> I want to be able to get at the described class in my shared
>>> behaviour. I'm
>>> sure an example will say it better than my words
>>>
>>> describe "my shared", :shared => true do
>>>
>>> it "should tell me what the class is its describing" do
>>> how_do_i_get_the_user_class_here
>>> end
>>>
>>> end
>>>
>>> describe User do
>>> it_should_behave_like "my shared"
>>>
>>> #...
>>> end
>>>
>>> So in my shared behaviour, how do I get access to the User class?
>>
>> There's no way to do this implicitly. i.e. rspec does not expose the
>> class. You'd have to have a method like described_class or something:
>>
>> describe "my shared", :shared => true do
>>
>> it "should tell me what the class is its describing" do
>> described_class.should do_something_I_care_about
>> end
>>
>> end
>>
>> describe User do
>> def described_class
>> User
>> end
>> ...
>> end
>>
>>
>
> However, if you do this:
>
> describe MyModule do # MyModule has a #hello method
> it "should be polite" do
> hello.should == 'How do you do'
> end
> end
>
> Modules are automatically mixed into your examples
>
> Aslak
>>
>>
>>
>>>
>>> Cheers
>>> Daniel
>>>
>>> _______________________________________________
>>> rspec-users mailing list
>>> rspec-users at rubyforge.org
>>> http://rubyforge.org/mailman/listinfo/rspec-users
>>>
>> _______________________________________________
>> rspec-users mailing list
>> rspec-users at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-users
>>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
More information about the rspec-users
mailing list