Skip to content

Instantly share code, notes, and snippets.

@myronmarston
Created February 19, 2013 15:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myronmarston/4986865 to your computer and use it in GitHub Desktop.
Save myronmarston/4986865 to your computer and use it in GitHub Desktop.
describe Company do
before { @company = Company.new }
describe "when address2" do
it_behaves_like "a text field", "address2", "a", Company.address2.limit do
let(:model) { @company }
end
end
end
# or...
describe Company do
let(:company) { Company.new }
describe "when address2" do
it_behaves_like "a text field", "address2", "a", Company.address2.limit do
let(:model) { company }
end
end
end
@azvirac
Copy link

azvirac commented Mar 12, 2013

Hello Myron,

I am new in rspec and i am trying to reuse this example.Scenario is similar, i need shared context that will have parameter passed so that I can use it in several tests. I wrote this:

shared_examples_for "shared" do |name|

it "should verify something has name" do
@homepage.text.include?(name)
end

end

in another file I have:

describe "test do
let (:t_name){"Airport"}

it "" do
etc
end

describe "reuse shared" do

it_behaves_like "shared" do
let(:name){t_name}
end
end
end

i tried with setting t_name as @t_name or $t_name but it does not work. I am getting can't convert nil into String.It looks like my variable is not visible in shared script. I also tried without setting let in it behaves like but instead setting it as it_behaves_like "shared", "Airport" and this works but i would really need to use parameters instead of values. Can you help me?

Thanky,
Alma

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment