Hi Evan, Maybe this text from the documentation explains it: "Shared examples let you describe behaviour of types or modules. When declared, a shared group's content is stored. It is only realized in the context of another example group, which provides any context the shared group needs to run.”
So if the context for the code is another example group, then maybe the variables it can access are those defined within that other example group. I don’t know, just trying to make sense of the behavior. Jack > On Jun 25, 2020, at 8:07 AM, Evan Brodie <[email protected]> wrote: > > Yes, Jack's analysis is correct. I placed my def method_name method > definition within the shared example block, not outside of it. > > I do a similar things when I write RSpec tests that used describe and context > blocks. I place method definition via def method_name within those blocks and > have no issues with accessing any of the let variables or even instance > variables of the test. When I'm outside of that describe or context block, > then naturally I cannot access that method anymore. Makes perfect sense. > Moreover, if I use a method outside of that block, then of course I cannot > access let variable from within the block. Neither of these situations are > what I'm dealing with here. > > Perhaps shared example blocks act differently than describe or context > blocks, in that their block parameters are not freely available to nested > method definition? I just want to make sure that we are all on the same page > though. > > On Thursday, June 25, 2020 at 10:46:09 AM UTC-4, Jack R-G wrote: > Hi Jon, > > I don’t think the original code looks like your example. It has the method > definition **inside** the “thing do” block. > > >> On Jun 25, 2020, at 7:30 AM, Jon Rowe <[email protected] <>> wrote: >> >> Hi Evan >> >> What I mean by standing ruby scoping are the rules surrounding how and when >> a variable is accessible. >> >> When a block is defined that takes variables, those variable names are >> considered to be local to the block (the same as a normal local variable) so >> are only available within that "scope” e.g. >> >> thing do |local_variable| >> >> # local variable is fine here >> >> method_name do >> # local variable is fine here too, but not in the method definition >> end >> end >> >> # but local_variable does not exist here >> >> def method_name >> # nor does local_variable exist here >> end >> >> Hope that helps! >> Cheers >> Jon Rowe >> --------------------------- >> [email protected] <> >> jonrowe.co.uk <http://jonrowe.co.uk/> >> >> On 25 June 2020 at 02:56, Evan Brodie wrote: >>> I admit that I don't fully understand the example you provided. I'm not >>> sure how it translates into RSpec code, nor what the connection is to >>> "standard Ruby scoping". >>> >>> Anyhow, what I got out of this thread is that "accessing shared example >>> block variables in a defined method is not possible". I'll use strategies >>> such as exposing the variable in a let variable or passing the values as >>> method parameters. Thank you all for the help. >>> >>> On Wednesday, June 24, 2020 at 7:16:37 AM UTC-4, Jon Rowe wrote: >> >> -- >> 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 view this discussion on the web visit >> https://groups.google.com/d/msgid/rspec/dejalu-217-93435473-ca39-406a-9ba5-8eb3ad02a4bb%40jonrowe.co.uk >> >> <https://groups.google.com/d/msgid/rspec/dejalu-217-93435473-ca39-406a-9ba5-8eb3ad02a4bb%40jonrowe.co.uk?utm_medium=email&utm_source=footer>. > > > -- > 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] > <mailto:[email protected]>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/rspec/b06a8dc3-8502-4f90-a48a-054bf7350cf1o%40googlegroups.com > > <https://groups.google.com/d/msgid/rspec/b06a8dc3-8502-4f90-a48a-054bf7350cf1o%40googlegroups.com?utm_medium=email&utm_source=footer>. -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/rspec/A98A23EB-B22E-466B-8A7B-53B396B612E6%40pobox.com.
