Ruby on rails 如何在没有“page”和“visit”方法的情况下重写请求规范?
在对capybara和rspec进行最新更改之前,允许请求规范使用Ruby on rails 如何在没有“page”和“visit”方法的情况下重写请求规范?,ruby-on-rails,rspec,capybara,rspec-rails,Ruby On Rails,Rspec,Capybara,Rspec Rails,在对capybara和rspec进行最新更改之前,允许请求规范使用页面和访问方法。集成测试运行良好,允许您跨模型、视图和控制器进行测试。所以测试像跟踪和不跟踪用户这样的东西很简单 describe "User" do context "Relationships" do let(:user) { FactoryGirl.create :user } let(:other_user) { FactoryGirl.create :user } before do
页面
和访问
方法。集成测试运行良好,允许您跨模型、视图和控制器进行测试。所以测试像跟踪和不跟踪用户这样的东西很简单
describe "User" do
context "Relationships" do
let(:user) { FactoryGirl.create :user }
let(:other_user) { FactoryGirl.create :user }
before do
sign_in user
end
describe "Following a user" do
before do
visit user_path(other_user)
end
it "will increment the followed user count" do
expect do
click_button "Follow"
end.to change(user.followeds, :count).by(1)
end
end
end
end
现在这是由capybara和rspec推荐的作为特性规范重写的请求规范
feature "Relationships" do
given!(:user) { FactoryGirl.create :user }
given!(:other_user) { FactoryGirl.create :user }
background do
sign_in user
end
scenario "following another user" do
visit user_path(other_user)
click_button "Follow"
expect(page).to have_button "Unfollow"
end
end
与使用页面
和访问
方法的请求规范相比,在功能规范中获得相同的细节似乎更加困难或不可能
任何人都可以演示如何重写请求规范,以便只使用响应
对象而不使用页面
和访问
我也知道将它们重新纳入请求规范,但不建议这样做
提前感谢我知道默认情况下,这些方法仅适用于功能规格,但为什么要重写测试?当我们升级时,我们只是将我们的
请求
目录移动到功能
。我知道你的意思,但是功能规格应该使用功能和场景,而不是描述和描述它。我只是想问,是否有人知道如何在不使用page
和visit
的情况下在请求规范中进行相同的测试,功能规范可以嵌套-@AndreyBotalov啊,谢谢你的提醒。我不知道这已经改变了。如果没有嵌套,很难测试某些情况。这很有帮助