我正在尝试在Michael Hartl的Ruby on Rails教程中进行第8.5章练习2.演习如下:
按照第8.3.3节中的示例,浏览用户和身份验证请求规范(即当前在spec/requests目录中的文件),并在spec/support/utilities.rb中定义实用程序函数,以将测试与实现分离.额外的功劳:将支持代码组织到单独的文件和模块中,并通过在spec帮助文件中正确包含模块来使一切工作正常.
例8.3.3:utilities.rb
include ApplicationHelper
def valid_signin(user)
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
end
RSpec::Matchers.define :have_error_message do |message|
match do |page|
page.should have_selector('div.alert.alert-error', text: message)
end
end
Run Code Online (Sandbox Code Playgroud)
已定义的valid_signin(user)函数用于以下块中authentication_pages_spec.rb并且工作正常.
describe "with valid information" do
let(:user){FactoryGirl.create(:user)}
before { valid_signin(user) }
it { should have_selector('title', text: user.name) }
it { should have_link('Profile', href: user_path(user)) }
it { should have_link('Sign out', href: signout_path) }
it { should_not have_link('Sign in', …Run Code Online (Sandbox Code Playgroud) 为了学习,有一个更短的方法:
if string.isdigit() == False :
我想:
if !string.isdigit() :和if !(string.isdigit()) :这两人都没有工作.