Is it possible for an rspec method to get the value of the parameter passed to it() in the local method? For example, if I want:
describe Me do
it "should figure this out"
puts "I " + SPEC_NAME
end
end
to print this:
I should figure this out
… what would I put for SPEC_NAME in the code sample?
Even better, how would a relatively new rubologist like me figure this out on his own?
The
descriptionmethod should do what you want. e.g.In terms of how to figure this out, I found it by looking in the RDocs for RSpec, starting by looking at the source of the it method to see how it works. You will then find that RSpec refers to the “it” string as the “description” so you can look for available methods that include description in their name.
I know it’s not much use to you right now, but as you learn more Ruby you’ll find it easier to read the code in libraries like RSpec and will develop an instinct for how they are likely to be implemented, which will help you look in the right places for things.