Sha256: f2b51662fa95562bb39147fa248e44fc12437157ded1ec4466c554ee9a4d986c

Contents?: true

Size: 1.62 KB

Versions: 3

Compression:

Stored size: 1.62 KB

Contents

# coding: utf-8
require "spec_helper"

describe Dech::Dena::FTP do
  let(:ftp) {
    described_class.new(
      products: [{id: "PRODUCT-CODE", price: 9800, "path" => "a:b", "name" => "productA"}],
      username: "username",
      password: "password",
      host:     "example.com"
    )
  }

  let(:net_ftp) {
    net_ftp = double("net_ftp")
    allow(net_ftp).to receive(:passive=)
    allow(net_ftp).to receive(:connect)
    allow(net_ftp).to receive(:login)
    allow(net_ftp).to receive(:close)
    expect(Net::FTP).to receive(:new).and_return(net_ftp)
    net_ftp
  }

  describe "initialize" do
    subject { ftp }
    it { is_expected.to be_an_instance_of(described_class) }
  end

  describe "#csv" do
    subject { ftp.csv }
    it { is_expected.to be_an_instance_of(Dech::Dena::CSV) }
  end

  describe "#ready?" do
    subject { ftp.ready? }

    context "Always" do
      it { is_expected.to be true }
    end
  end

  describe "#upload!" do
    subject{ lambda{ ftp.upload! } }

    it "should upload CSV file to the path on FTP server" do
      expect(net_ftp).to receive(:storlines)
      subject.call
    end
  end

  describe "#upload" do
    subject{ lambda{ ftp.upload } }

    context "FTP server is ready" do
      it "should call #upload!" do
        expect(ftp).to receive(:ready?).and_return(true)
        expect(ftp).to receive(:upload!).and_return(true)
        subject.call
      end
    end

    context "FTP server is not ready" do
      it "should not call #upload!" do
        expect(ftp).to receive(:ready?).and_return(false)
        expect(ftp).not_to receive(:upload!)
        subject.call
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dech-0.1.0 spec/dech/dena/ftp_spec.rb
dech-0.0.7 spec/dech/dena/ftp_spec.rb
dech-0.0.6 spec/dech/dena/ftp_spec.rb