2017-01-29 3 views
0

이 프로세스를 다루기 위해 this Stack Overflow question에 기반한 다음 사양을 사용하려고했습니다.하이 라인 스텁을 사용하는 3 가지 레이크 작업

현재 사양 ...

describe 'rake task myapp:data:load:from' do 
    include_context 'rake' 
    let(:task_path) { 'tasks/data.rake' } 

    describe ':range', focus: true do 
    let(:created_before) { '2017-01-02' } 
    let(:created_after) { '2017-01-01' } 
    let(:task_name) { 'myapp:data:load:range' } 
    before do 
     allow(highline).to receive(:ask).and_return(true) 
     # rubocop:disable all 
     allow_any_instance_of(Object).to receive(:created_after).and_return(created_after) 
     allow_any_instance_of(Object).to receive(:created_before).and_return(created_before) 
     # rubocop:enable all 
    end 

    it 'processes from a specified starting point' do 
     # expect(Resque).to receive(:enqueue).with(AmazonMws::ImportOrdersJob, created_from: created_from) 
     invoke_task.invoke 
    end 
    end 

    describe ':from' do 
    let(:created_from) { '2017-01-01' } 
    let(:task_name) { 'myapp:data:load:from' } 
    before do 
     allow(highline).to receive(:ask).and_return(created_from) 
    end 

    it 'processes from a specified starting point' do 
     expect(Resque).to receive(:enqueue).with(AmazonMws::ImportOrdersJob, created_from: created_from) 
     invoke_task.invoke 
    end 
    end 
end 

레이크 작업 ...

namespace :myapp do 
    namespace :data do 
    namespace :load do 
     desc 'Enqueue a range of dates by provider' 
     task range: :environment do 
     cli = HighLine.new 
     msg('Select the dates for your data pull. Format: yyyy-mm-dd') 
     created_before = cli.ask('Data created_before? ', Date) 
     created_after = cli.ask('Data created_after? ', Date) 

     if created_after >= created_before 
      error_msg('The created_after date must be less than created_before!') 
      exit 
     else 
      Resque.enqueue(AmazonMws::ImportOrdersJob, created_before: created_before, created_after: created_after) 
     end 
     end 

     desc 'Enqueue from a specified date by provider' 
     task from: :environment do 
     cli = HighLine.new 
     msg('Select the date for your data pull. Format: yyyy-mm-dd') 
     created_from = cli.ask('Data created_from? ', Date) 
     Resque.enqueue(AmazonMws::ImportOrdersJob, created_from: created_from) 
     end 
    end 
    end 
end 

spec_helper.rb

require 'rubygems' 

ENV['RAILS_ENV'] ||= 'test' 

require File.expand_path('../../config/environment', __FILE__) 

# Prevent database truncation if the environment is production 
abort('The Rails environment is running in production mode!') if Rails.env.production? 

require 'rspec/rails' 
require 'require_all' 
require 'shoulda/matchers' 
require 'pry' 
require 'webmock/rspec' 
require 'vcr' 
require 'json_matchers/rspec' 

# Only Allow LocalHost Tests! 
WebMock.disable_net_connect!(allow_localhost: true) 

# Requires supporting ruby files with custom matchers and macros, etc, 
# in spec/support/ and its subdirectories. 
Dir[Rails.root.join('spec/concerns/**/*.rb')].each { |f| require f } 
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } 

# Checks for pending migrations before tests are run. 
# If you are not using ActiveRecord, you can remove this line. 
ActiveRecord::Migration.maintain_test_schema! 

# Model Specs   => type: :model 
# Controller Specs  => type: :controller 
# Request Specs  => type: :request 
# Feature Specs  => type: :feature 
# Service Specs  => type: :service 
# View Specs   => type: :view 
# Helper Specs   => type: :helper 
# Mailer Specs   => type: :mailer 
# Routing Specs  => type: :routing 
# Constraint Specs  => type: :constraint 

Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } 

RSpec.configure do |config| 
    config.order = 'random' 
    config.seed = srand % 0xFFFF 
    config.infer_spec_type_from_file_location! 
    config.raise_errors_for_deprecations! 
    config.use_transactional_fixtures = false 
    config.infer_base_class_for_anonymous_controllers = false 

    config.filter_run focus: true 
    config.run_all_when_everything_filtered = true 

    config.before(:each) { GC.disable } 
    config.after(:each) { GC.enable } 
    config.include JsonSpec::Helpers 
    config.include LoadFixtureHelper 

    config.before(:all) do 
    Rails.cache.clear 
    end 
end 

방법 두 개의 별도 Ask 호출을 생략합니까? 바로 지금, 철자가 틀린 후에 나는 올바르게 작동하는 하나의 호출을 가지고있는 다른 레이크 작업을 가지고있다.

allow(highline).to receive(:call).with('Data created_before? ', Date).and_return(true) 
allow(highline).to receive(:call).with('Data created_after? ', Date).and_return(false) 
+0

무엇에 대한 스텁 실패 : – oolong

+0

@oolong 방금 추가했습니다. 죄송합니다. –

+0

rspec 3을 사용하고 있습니까? spec 파일 상단에'rails_helper'를 포함 시키려고 했습니까? – oolong

답변

0

, 당신은 당신과 같이 할 수 있습니다에 with를 전달할 수 range 작업에서 두 ​​개의 서로 다른 통화를 스텁하려면? 오류를 포함시킬 수 있습니까?
+0

님, 고마워요. –