Created
February 19, 2013 15:29
-
-
Save myronmarston/4986865 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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