यदि आप आरएसपीईसी का उपयोग कर रहे हैं, तो निश्चित रूप से 'परिवर्तन' जाने का रास्ता होना चाहिए। यहां दो उदाहरण एक नकारात्मक कर रहे हैं और एक सकारात्मक एक तो तुम वाक्य रचना का अनुभव हो सकता है:
RSpec.describe "UsersSignups", type: :request do
describe "signing up with invalid information" do
it "should not work and should go back to the signup form" do
get signup_path
expect do
post users_path, user: {
first_name: "",
last_name: "miki",
email: "[email protected]",
password: "buajaja",
password_confirmation: "juababa"
}
end.to_not change{ User.count }
expect(response).to render_template(:new)
expect(response.body).to include('errors')
end
end
describe "signing up with valid information" do
it "should work and should redirect to user's show view" do
get signup_path
expect do
post_via_redirect users_path, user: {
first_name: "Julito",
last_name: "Triculi",
email: "[email protected]",
password: "worldtriculi",
password_confirmation: "worldtriculi"
}
end.to change{ User.count }.from(0).to(1)
expect(response).to render_template(:show)
expect(flash[:success]).to_not be(nil)
end
end
ऐसा लगता है कि आप Rspec के साथ assert_difference मणि, सही उपयोग कर रहे हैं? मुझे लगता है कि आपको इसे 'इसे' ब्लॉक में लपेटने की ज़रूरत है। –
मैं इसे ब्लॉक में रखने की कोशिश करता हूं, लेकिन अभी भी यह त्रुटि –