iwa*_*bed 5 integration-testing rspec webrat ruby-on-rails-3
我现在正在学习测试,但是我在Webrat上找不到使用表单字段的问题,fill_in即使我已经验证它在正确的页面上.Webrat是否使用字段名称或ID?我尝试使用Ruby符号和表单名称来访问该字段,但在我的情况下都不起作用.你看到我的实施有什么不对吗?
错误消息:
5) Forwarding should forward the user to the requested page after signin
Failure/Error: integration_sign_in(user)
Could not find field: :email
Run Code Online (Sandbox Code Playgroud)
测试代码:
it "should forward the user to the requested page after signin" do
user = Factory(:user)
visit edit_user_path(user)
# The test automatically follows the redirect to the signin page
puts current_url
integration_sign_in(user)
# The test follows the redirect again, this time to users/edit
response.should render_template('users/edit')
end
Run Code Online (Sandbox Code Playgroud)
其中,integration_sign_in在spec_helper.rb
def integration_sign_in(user)
fill_in :email, :with => user.email
fill_in :password, :with => user.password
click_button
end
Run Code Online (Sandbox Code Playgroud)
表单字段HTML:
<form action='/sessions' class='mtm' id='sign-in-form' method='post'>
<input name='authenticity_token' type='hidden' value='iIIqT6bUwiJkpqpgxm5sjAj3egrNcEgeXPsYmbKQ02U='>
<div class='landingSignInForm'>
<label class='mas signin-label' for='email'>E-mail:</label>
<input class="mls ras" id="email" name="email" placeholder="e-mail address" type="text" />
<label class='mas signin-label' for='password'>Password:</label>
<input class="mls ras" id="password" name="password" placeholder="password" type="password" />
<input checked='checked' class='mls mtm' name='remember' type='checkbox' value='permanent'>
<span class='remember-me-label'>Keep me signed in</span>
<input class='mls mvm ram medium silver button' name='submit' type='submit' value='Sign in'>
<a class='forgot-password' href='#'>Forget your password?</a>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
您是否尝试过使用 css 选择器作为 ID 而不仅仅是传递匹配的符号?我尝试简要阅读 webrat 源代码,以确定它是否在内部将符号视为字符串,想知道这是否是您的问题。我找不到fill_in :symbol仅使用 webrat 语法的任何示例fill_in 'string'
尝试这个:
def integration_sign_in(user)
fill_in 'email', :with => user.email
fill_in 'password', :with => user.password
click_button
end
Run Code Online (Sandbox Code Playgroud)
或者你的 id 的 css 选择器路由:
def integration_sign_in(user)
fill_in '#email', :with => user.email
fill_in '#password', :with => user.password
click_button
end
Run Code Online (Sandbox Code Playgroud)