我环顾四周,无法弄清这个错误。
在运行规范时,在绑定撬为Errno::ECONNREFUSED: Failed to open TCP connection to localhost:3000
的情况下,我得到此错误。关于如何解决它的任何想法?
当我运行开发Rails服务器时,错误消失了,代码开始运行。
10: def call
=> 11: binding.pry
12: image = MiniMagick::Image.open(url)
13: end
[1] pry(#<ResizeImage>)> image = MiniMagick::Image.open(url)
Errno::ECONNREFUSED: Failed to open TCP connection to localhost:3000 (Connection refused - connect(2) for "localhost" port 3000)
from /Users/josephkonop/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/net/http.rb:939:in `rescue in block in connect'
这是代码
class ResizeImage
attr_reader :url, :width, :height
def initialize(params)
@url = params[:url]
@width = params[:width]
@height = params[:height]
end
def call
binding.pry
image = MiniMagick::Image.open(url)
end
end
The spec:
RSpec.describe 'Image Resizer', type: :request do
describe '#create' do
context 'when valid params' do
let(:image_url) { ActionController::Base.helpers.asset_path("cat.jpg") }
let(:width) { 300 }
let(:height) { 200 }
before do
post "/api/v1/resize?url=#{image_url}&width=#{width}&height=#{height}"
end
it 'response' do
expect(response.body).to eq('')
end
end
end
end
Test.rb
config.action_controller.asset_host = 'http://localhost:3000'