我使用Faraday和Github-Api宝石来记录Github的用户。为了测试任何类型的功能,我必须模仿这种行为。我想在我的规范中,我应该说“如果调用新动作(这是ping github-api)”,然后重定向到创建动作并传递创建用户所需的参数。 “我不完全确定如何做到这一点。我意识到有Oauth的解决方案,带有帮助方法的模块来模拟这种行为,但我正在为其他人构建的应用程序添加测试,因此它必须保持原样。任何帮助或指针将不胜感激。我对测试也很陌生,所以请随意评论测试本身。
require "rails_helper"
RSpec.feature "User submits a project" do
scenario "they see the index page for their projects" do
project = create(:project)
visit '/projects/new'
fill_in "project_title", with: project_title
fill_in "project_project_type", with: project_project_type
fill_in "project_description", with: project_description
fill_in "project_starts_at", with: project_starts_at
click_on "Create Project"
redirect_to '/projects'
expect(page).to have_project_title
end
end
def new
redirect_to "githubapiurlgoeshere"
end
def create
@user = User.find_or_create_from_auth_hash(auth_hash)
if @user.save
session[:token] = @user.token
session[:user_id] = @user.id
redirect_to root_path
else
flash[:notice] = "message here"
redirect_to root_path
end
end
答案 0 :(得分:1)
webmock(https://github.com/bblimke/webmock)?它将允许您使用预定义的响应模拟与Github的连接,因此它将尽可能接近现实+您可以在响应中定义变量