相关疑难解决方法(0)

使用Rspec和Rack :: Test测试REST-API响应

我有点难过.我有以下集成测试:

require "spec_helper"

describe "/foods", :type => :api do
  include Rack::Test::Methods

  let(:current_user) { create_user! }
  let(:host) { "http://www.example.com" }

  before do
    login(current_user)
    @food = FactoryGirl.create_list(:food, 10, :user => current_user)
  end

  context "viewing all foods owned by user" do

    it "as JSON" do
      get "/foods", :format => :json

      foods_json = current_user.foods.to_json
      last_response.body.should eql(foods_json)
      last_response.status.should eql(200)

      foods = JSON.parse(response.body)

      foods.any? do |f|
        f["food"]["user_id"] == current_user.id
      end.should be_true

      foods.any? do |f|
        f["food"]["user_id"] != current_user.id
      end.should be_false
    end

  end

  context "creating a food item" …
Run Code Online (Sandbox Code Playgroud)

ruby api integration-testing rspec ruby-on-rails

15
推荐指数
1
解决办法
7746
查看次数

标签 统计

api ×1

integration-testing ×1

rspec ×1

ruby ×1

ruby-on-rails ×1