Module: NeAPI::Testing::RSpecHelpers

Defined in:
lib/ne_api/testing/rspec_helpers.rb

Overview

RSpec用ヘルパーメソッド

Examples:

spec/rails_helper.rb での設定

require 'ne_api/testing'

RSpec.configure do |config|
  config.include NeAPI::Testing::RSpecHelpers
end

テストコードでの使用

RSpec.describe OrderService do
  it "受注を取得する" do
    with_fake_ne_api do |fake|
      fake.stub(:receiveorder_base_search, [ne_receive_order])
      # ...
    end
  end
end

Instance Method Summary collapse

Instance Method Details

#fake_ne_auth(**options) ⇒ FakeAuth

FakeAuthインスタンスを生成

Parameters:

  • options (Hash)

    初期化オプション

Returns:



35
36
37
# File 'lib/ne_api/testing/rspec_helpers.rb', line 35

def fake_ne_auth(**options)
  NeAPI::Testing::FakeAuth.new(**options)
end

#fake_ne_master(**options) ⇒ FakeMaster

FakeMasterインスタンスを生成

Parameters:

  • options (Hash)

    初期化オプション

Returns:



27
28
29
# File 'lib/ne_api/testing/rspec_helpers.rb', line 27

def fake_ne_master(**options)
  NeAPI::Testing::FakeMaster.new(**options)
end

#ne_company_info(**attrs) ⇒ Object

会社情報を生成



112
113
114
# File 'lib/ne_api/testing/rspec_helpers.rb', line 112

def ne_company_info(**attrs)
  NeAPI::Testing::ResponseFactory.company_info(attrs)
end

#ne_error(**attrs) ⇒ Object

エラーレスポンスを生成



136
137
138
# File 'lib/ne_api/testing/rspec_helpers.rb', line 136

def ne_error(**attrs)
  NeAPI::Testing::ResponseFactory.error(**attrs)
end

#ne_goods(**attrs) ⇒ Object

商品データを生成



70
71
72
# File 'lib/ne_api/testing/rspec_helpers.rb', line 70

def ne_goods(**attrs)
  NeAPI::Testing::ResponseFactory.goods(attrs)
end

#ne_goods_list(count = 3, &block) ⇒ Object

商品リストを生成



76
77
78
# File 'lib/ne_api/testing/rspec_helpers.rb', line 76

def ne_goods_list(count = 3, &block)
  NeAPI::Testing::ResponseFactory.goods_list(count, &block)
end

#ne_receive_order(**attrs) ⇒ Object

受注データを生成



94
95
96
# File 'lib/ne_api/testing/rspec_helpers.rb', line 94

def ne_receive_order(**attrs)
  NeAPI::Testing::ResponseFactory.receive_order(attrs)
end

#ne_receive_order_list(count = 3, &block) ⇒ Object

受注リストを生成



100
101
102
# File 'lib/ne_api/testing/rspec_helpers.rb', line 100

def ne_receive_order_list(count = 3, &block)
  NeAPI::Testing::ResponseFactory.receive_order_list(count, &block)
end

#ne_receive_order_row(**attrs) ⇒ Object

受注明細データを生成



106
107
108
# File 'lib/ne_api/testing/rspec_helpers.rb', line 106

def ne_receive_order_row(**attrs)
  NeAPI::Testing::ResponseFactory.receive_order_row(attrs)
end

#ne_shop(**attrs) ⇒ Object

店舗データを生成



124
125
126
# File 'lib/ne_api/testing/rspec_helpers.rb', line 124

def ne_shop(**attrs)
  NeAPI::Testing::ResponseFactory.shop(attrs)
end

#ne_stock(**attrs) ⇒ Object

在庫データを生成



82
83
84
# File 'lib/ne_api/testing/rspec_helpers.rb', line 82

def ne_stock(**attrs)
  NeAPI::Testing::ResponseFactory.stock(attrs)
end

#ne_stock_list(count = 3, &block) ⇒ Object

在庫リストを生成



88
89
90
# File 'lib/ne_api/testing/rspec_helpers.rb', line 88

def ne_stock_list(count = 3, &block)
  NeAPI::Testing::ResponseFactory.stock_list(count, &block)
end

#ne_success_response(**attrs) ⇒ Object

成功レスポンスを生成



142
143
144
# File 'lib/ne_api/testing/rspec_helpers.rb', line 142

def ne_success_response(**attrs)
  NeAPI::Testing::ResponseFactory.success_response(**attrs)
end

#ne_user_info(**attrs) ⇒ Object

ユーザー情報を生成



118
119
120
# File 'lib/ne_api/testing/rspec_helpers.rb', line 118

def (**attrs)
  NeAPI::Testing::ResponseFactory.(attrs)
end

#ne_warehouse_stock(**attrs) ⇒ Object

倉庫在庫データを生成



130
131
132
# File 'lib/ne_api/testing/rspec_helpers.rb', line 130

def ne_warehouse_stock(**attrs)
  NeAPI::Testing::ResponseFactory.warehouse_stock(attrs)
end

#with_fake_ne_api(**options) {|FakeMaster| ... } ⇒ Object

NeAPI::Master.newをFakeMasterに差し替えてブロックを実行

Examples:

with_fake_ne_api do |fake|
  fake.stub(:master_goods_search, [ne_goods])
  service = MyService.new  # 内部でNeAPI::Master.newを呼ぶ
  service.call
end

Yields:

Returns:

  • (Object)

    ブロックの戻り値



50
51
52
53
54
# File 'lib/ne_api/testing/rspec_helpers.rb', line 50

def with_fake_ne_api(**options)
  fake = fake_ne_master(**options)
  allow(NeAPI::Master).to receive(:new).and_return(fake)
  yield fake
end

#with_fake_ne_auth(**options) {|FakeAuth| ... } ⇒ Object

NeAPI::Auth.newをFakeAuthに差し替えてブロックを実行

Yields:

  • (FakeAuth)

    FakeAuthインスタンス

Returns:

  • (Object)

    ブロックの戻り値



60
61
62
63
64
# File 'lib/ne_api/testing/rspec_helpers.rb', line 60

def with_fake_ne_auth(**options)
  fake = fake_ne_auth(**options)
  allow(NeAPI::Auth).to receive(:new).and_return(fake)
  yield fake
end