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] <javascript:>> > 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] <javascript:> > 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] <javascript:>. > 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]. To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/b06a8dc3-8502-4f90-a48a-054bf7350cf1o%40googlegroups.com.
