Answer the question
In order to leave comments, you need to log in
Rspec: how to pass arguments to test post request?
controller code
class CalcController < ApplicationController
include CalcHelper
def index
end
def count
result = /* модифицируем params[:args] */
respond_to do |format|
format.json { render json: {result: result.to_s} }
end
end
require 'rails_helper'
require 'json'
RSpec.describe CalcController, type: :controller do
describe "count" do
it "counts_sum" do
testdata = {:args => [4,5], :op => 'add' }
post :count, :parameters => testdata, format: :json
expect(JSON.parse(response.body)).to eq({"result" => '9'})
end
end
end
Answer the question
In order to leave comments, you need to log in
:params
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question