我已经将Devise安装并集成到我的应用程序中,现在我正在构建其测试套件.我正在使用Rails 4.2.1附带的默认测试套件(Test :: Unit?),目前正在使用集成套件.
综合测试:
def setup
@user = User.create(email: "user@hlist.com",
encrypted_password: Devise.bcrypt(User, 'password1'))
@post = { title: "This is the title",
content: "Detailed comment."*10,
phone: 9991118888,
email: "email@hlist.com",
user_id: users(:spiderman).id }
@p = @user.posts.build(@post)
end
test "creates a new post successfully" do
sign_in_as(@user)
get new_post_path(@user)
assert_template 'posts/new'
assert_difference 'Post.count', 1 do
post posts_path, post: @post
end
assert_template 'posts/show'
end
Run Code Online (Sandbox Code Playgroud)
我还在test_helper.rb文件中创建了以下方法:
def sign_in_as(user)
post_via_redirect user_session_path, 'user[:email]' => user.email,
'user[:encrypted_password]' => Devise.bcrypt(User, 'password1')
end
Run Code Online (Sandbox Code Playgroud)
但是,运行测试时出现以下错误:
1) Failure:
PostsCrudTest#test_creates_a_new_post_successfully [/Users/harishramachandran/dropbox/documents/harish/coding/workspace/h_list/test/integration/posts_crud_test.rb:19]: …Run Code Online (Sandbox Code Playgroud) ruby integration-testing ruby-on-rails devise ruby-on-rails-4