I'll leave it for someone more familiar with functionality/best practices.

On Tue, Mar 3, 2015 at 2:27 PM, Myron Marston <[email protected]>
wrote:

> Want to open a PR fixing our README :)?
>
> On Tue, Mar 3, 2015 at 11:04 AM, <[email protected]> wrote:
>
>>
>>
>> On Saturday, February 28, 2015 at 3:00:07 PM UTC-5, Myron Marston wrote:
>>>
>>>
>>>
>>> On Saturday, February 28, 2015 at 11:57:30 AM UTC-8, Myron Marston wrote:
>>>>
>>>> On Saturday, February 28, 2015 at 11:48:01 AM UTC-8,
>>>> [email protected] wrote:
>>>>>
>>>>> Consider this (simplified) snippet. RSpec 3.1.7
>>>>>
>>>>> RSpec.describe MyController, :type => :controller do
>>>>>
>>>>>   describe "PUT #update" do
>>>>>
>>>>>     before(:example) do
>>>>>       puts self.class                          #=>
>>>>> RSpec::ExampleGroups::MyController::PUTUpdate
>>>>>       puts self.class.example.description      #=> "example at
>>>>> ./spec/controllers/my_controller_spec.rb:xxx"
>>>>>       puts self.class.example.full_description #=> "MyController PUT
>>>>> update"
>>>>>       puts example.description                 #=> undefined local
>>>>> variable or method 'example'
>>>>>
>>>>>     end
>>>>>
>>>>>
>>>>>     it "should update things" do
>>>>>       puts self.class                          #=>
>>>>> RSpec::ExampleGroups::MyController::PUTUpdate
>>>>>       puts self.class.example.description      #=> "example at
>>>>> ./spec/controllers/my_controller_spec.rb:xxx"
>>>>>       puts self.class.example.full_description #=> "MyController PUT
>>>>> update"
>>>>>       puts example.description                 #=> undefined local
>>>>> variable or method 'example'
>>>>>     end
>>>>>   end
>>>>> end
>>>>>
>>>>>
>>>>> I'm seeing some odd results when getting the metadata and description
>>>>> values for examples.
>>>>>
>>>>> None of the Example instance methods work. Everything behaves as an
>>>>> ExampleGroup. I'm not sure if this is intended.
>>>>>
>>>>> From the rspec-core README https://github.com/
>>>>> rspec/rspec-core#metadata
>>>>>
>>>>>
>>>>> it "does something" do
>>>>>   expect(example.metadata[:description]).to eq("does something")
>>>>> end
>>>>>
>>>>> This does not work. Am I doing something wrong?
>>>>>
>>>>
>>>> Our README is out of date -- it was written against RSpec 2 but we have
>>>> no tooling that validates its correctness and we forgot to update that
>>>> example for the changes in RSpec 3.  That's one advantage of the cukes --
>>>> they are self-validating and thus always correct :).
>>>>
>>>> Anyhow, in RSpec 3, we removed the `example` method, in favor of
>>>> passing an arg to the `it`, `before`, `after`, `let`, etc. blocks:
>>>>
>>>> http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/
>>>> #dsl-methods-yield-the-example-as-an-argument
>>>>
>>>> So change `before(:example) do` to `before(:example) do |example|` and
>>>> `it "..." do` to `it "..." do |example|` and it should work.
>>>>
>>>> Everything behaves as an ExampleGroup. I'm not sure if this is intended.
>>>>
>>>>
>>>> It is.  Every example is evaluated in the context of an instance of the
>>>> example group class of which it is a part.  This mirrors typical xUnit
>>>> structure where you've got TestCase classes and tests are instance methods
>>>> of those classes.  This in turn provides us with the desired scoping and
>>>> inheritance semantics that you'd want.  Helper methods defined in the
>>>> example group can be automatically called from within the `it` block
>>>> without doing anything special to support that.
>>>>
>>>> The `example` object yielded to these methods is a special object that
>>>> keeps track of the state of a particular example, exposing its metadata,
>>>> its execution result, etc.
>>>>
>>>> HTH,
>>>> Myron
>>>>
>>>
>>> One other thing that's probably confusing there: when you call
>>> `self.class.example` you are defining a new example.  `it` is simply an
>>> alias of `example`.  That's why `self.class.example.description` has
>>> the location rather than the description of the `it` example -- because
>>> you're getting the description off of a new, anonymous example, so it is
>>> using the location description as the example description.
>>>
>>> Myron
>>>
>>
>> Got it. Works as expected. Thanks!
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "rspec" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/rspec/5fd08772-9a0d-4855-870f-d0aa9e66fd46%40googlegroups.com
>> <https://groups.google.com/d/msgid/rspec/5fd08772-9a0d-4855-870f-d0aa9e66fd46%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "rspec" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/rspec/JhOMtubpZNY/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rspec/CADUxQmvb6gOthJvcfL7uEnJKd2e5g59cVDFV5po712Nzdu4Odg%40mail.gmail.com
> <https://groups.google.com/d/msgid/rspec/CADUxQmvb6gOthJvcfL7uEnJKd2e5g59cVDFV5po712Nzdu4Odg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/CAC5o3HV2bNw%3DtX4cLmAHcvdn0f%3D4nThZUfcNXx65JH3F0sz6gQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to