A
A
arlovski2015-02-12 17:43:40
Ruby on Rails
arlovski, 2015-02-12 17:43:40

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

test code
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

does not work.
I can't figure out what is the syntax for passing parameters when testing a request?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Polushkin, 2015-02-12
@arlovski

:params

https://github.com/rails/rails/blob/master/actionp...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question