Sunday, 18 August 2013

How do I define a variable in a RSpec feature?

How do I define a variable in a RSpec feature?

Im learning Rails 4 and and trying to write some tests using Rspec and
capybara. Im writing a feature test for my users and I'm trying to test a
user signing in.
feature "User" do
scenario "A user signs in" do
let(:user) { FactoryGirl.create(:user) }
visit signin_path
fill_in "Username", with: user.username
fill_in "Password", with: "123456"
click_button "Log in"
expect(page).to have_content(user.username)
end
end
Its telling me that let is an undefined method. and I'm sure that the
problem is that it is in a feature/scenario test. How do I define the user
in this kind of test?
Also, in a describe/it request test like this
describe "Something" do
it "should do something" do
expect(page).to have_content{"...")
end
end
I can shorten it like this
describe "Something" do
subject { page }
it { should have_content("...") }
end
Is there a way to shorten the expect(page)..... in a scenario? Thanks.

No comments:

Post a Comment