diff --git a/collmex-ruby.gemspec b/collmex-ruby.gemspec index 067305f..fe89acd 100644 --- a/collmex-ruby.gemspec +++ b/collmex-ruby.gemspec @@ -1,7 +1,7 @@ Gem::Specification.new do |s| s.name = 'collmex-ruby' - s.version = '0.2.0' - s.date = '2012-07-29' + s.version = '1.2.0' + s.date = '2024-03-01' s.summary = "A ruby api lib for collmex" s.description = "A lib written in ruby that talks to the german accounting software collmex." s.authors = ["Roman Lehnert"] @@ -9,8 +9,9 @@ Gem::Specification.new do |s| s.files = Dir['lib/**/*.rb'] s.homepage = 'https://github.com/romanlehnert/collmex-ruby' s.license = "MIT" - s.add_development_dependency 'json', '~> 1.8.0' - s.add_development_dependency 'rspec', '~> 2.5' + s.add_dependency 'csv' + s.add_dependency 'base64' + s.add_development_dependency 'rspec' s.add_development_dependency 'webmock' s.add_development_dependency 'vcr' s.test_files = Dir.glob("{spec,test}/**/*.rb") diff --git a/lib/collmex/api.rb b/lib/collmex/api.rb index a2cea5b..3e5b436 100644 --- a/lib/collmex/api.rb +++ b/lib/collmex/api.rb @@ -20,7 +20,7 @@ def self.line_class_exists?(class_name) # from Collmex::Api::Line def self.parse_line(line) # in case the line is already an array - if line.is_a?(Array) && line.first.is_a?(String) || line.is_a?(String) && line = CSV.parse_line(line, Collmex.csv_opts) + if line.is_a?(Array) && line.first.is_a?(String) || line.is_a?(String) && line = CSV.parse_line(line, **Collmex.csv_opts) identifyer = line.first.split(/_|-/).map { |s| s.downcase.capitalize }.join if self.line_class_exists?(identifyer) Collmex::Api.const_get(identifyer).new(line) @@ -95,4 +95,5 @@ def self.stringify_currency(data) require "collmex/api/sales_order_get" require "collmex/api/accbal_get" require "collmex/api/accbal" +require "collmex/api/cmxums" diff --git a/lib/collmex/api/cmxknd.rb b/lib/collmex/api/cmxknd.rb index 78a75d8..47cf642 100644 --- a/lib/collmex/api/cmxknd.rb +++ b/lib/collmex/api/cmxknd.rb @@ -45,6 +45,9 @@ def self.specification { name: :output_language , type: :integer }, { name: :email_cc , type: :string }, { name: :phone_2 , type: :string }, + { name: :sepa_mandate_reference, type: :string }, + { name: :sepa_mandate_signature_date, type: :date }, + { name: :dunning_block , type: :integer }, ] end end diff --git a/lib/collmex/api/cmxums.rb b/lib/collmex/api/cmxums.rb new file mode 100644 index 0000000..679ec6e --- /dev/null +++ b/lib/collmex/api/cmxums.rb @@ -0,0 +1,36 @@ +class Collmex::Api::Cmxums < Collmex::Api::Line + def self.specification + [ + { name: :_1_identifyer, type: :string, fix: "CMXUMS"}, # 1 + { name: :_2_customer_id, type: :integer}, + { name: :_3_company_id, type: :integer, default: 1}, + { name: :_4_receipt_date, type: :date }, + { name: :_5_receipt_number, type: :string }, # 5 + { name: :_6_net_value_full_tax, type: :currency }, + { name: :_7_tax_value_full_tax, type: :currency }, + { name: :_8_net_value_half_tax, type: :currency }, + { name: :_9_tax_value_half_tax, type: :currency }, + { name: :_10_net_value_inter_eu_trade, type: :currency }, # 10 + { name: :_11_net_value_export, type: :currency }, + { name: :_12_account_revenue_tax_free, type: :integer }, + { name: :_13_value_revenue_tax_free, type: :currency }, + { name: :_14_currency_code, type: :string }, + { name: :_15_contra_account, type: :integer }, # 15 + { name: :_16_receipt_type, type: :integer, default: 0 }, + { name: :_17_receipt_text, type: :string }, + { name: :_18_payment_term, type: :integer }, + { name: :_19_account_full_tax, type: :integer }, + { name: :_20_account_half_tax, type: :integer }, # 20 + { name: :_21_reserved21, type: :string }, + { name: :_22_reserved22, type: :string }, + { name: :_23_storno, type: :integer }, + { name: :_24_final_receipt, type: :string }, + { name: :_25_revenue_type, type: :integer }, # 25 + { name: :_26_system_name, type: :string }, + { name: :_27_charge_against_receipt_number, type: :string }, + { name: :_28_cost_center, type: :string } + ] + end +end + + diff --git a/lib/collmex/api/line.rb b/lib/collmex/api/line.rb index a5afed7..ef0d6f3 100644 --- a/lib/collmex/api/line.rb +++ b/lib/collmex/api/line.rb @@ -26,7 +26,7 @@ def self.hashify(data) hash = self.default_hash fields_spec = self.specification - if data.is_a?(Array) || data.is_a?(String) && data = CSV.parse_line(data,Collmex.csv_opts) + if data.is_a?(Array) || data.is_a?(String) && data = CSV.parse_line(data, **Collmex.csv_opts) fields_spec.each_with_index do |field_spec, index| if !data[index].nil? && !field_spec.has_key?(:fix) hash[field_spec[:name]] = Collmex::Api.parse_field(data[index], field_spec[:type]) @@ -70,7 +70,7 @@ def to_stringified_array def to_csv - CSV.generate_line(self.to_stringified_array, Collmex.csv_opts) + CSV.generate_line(self.to_stringified_array, **Collmex.csv_opts) end def to_h diff --git a/lib/collmex/request.rb b/lib/collmex/request.rb index 7f80619..9878378 100644 --- a/lib/collmex/request.rb +++ b/lib/collmex/request.rb @@ -82,7 +82,7 @@ def execute @raw_response[:string] = response.body.encode("UTF-8") begin - @raw_response[:array] = CSV.parse(@raw_response[:string], Collmex.csv_opts) + @raw_response[:array] = CSV.parse(@raw_response[:string], **Collmex.csv_opts) rescue => e STDERR.puts "CSV.parse failed with string: #{@raw_response[:string]}" if self.debug raise e diff --git a/spec/lib/collmex/api_spec.rb b/spec/lib/collmex/api_spec.rb index 215da49..9768b8f 100644 --- a/spec/lib/collmex/api_spec.rb +++ b/spec/lib/collmex/api_spec.rb @@ -22,22 +22,22 @@ describe ".is_a_collmex_api_line_obj?" do it "should fail for an array" do a = Array.new - described_class.is_a_collmex_api_line_obj?(a).should be_false + expect(described_class.is_a_collmex_api_line_obj?(a)).to be_falsey end it "should succeed for a Collmex::Api Object" do b = Collmex::Api::AccdocGet.new() - described_class.is_a_collmex_api_line_obj?(b).should be_true + expect(described_class.is_a_collmex_api_line_obj?(b)).to be_truthy end end describe ".line_class_exists?" do it "should be true for a existing class" do - Collmex::Api.line_class_exists?("Line").should be true + expect(Collmex::Api.line_class_exists?("Line")).to be true end it "should be false for a non existant class" do - Collmex::Api.line_class_exists?("asdasdasdasdaaBla").should be false + expect(Collmex::Api.line_class_exists?("asdasdasdasdaaBla")).to be false end end @@ -73,7 +73,7 @@ ] tests.each do |test| it "should represent #{test[:type]} \"#{test[:input].inspect}\" as \"#{test[:outcome]}\"" do - described_class.stringify(test[:input],test[:type]).should === test[:outcome] + expect(described_class.stringify(test[:input],test[:type])).to be === test[:outcome] end end end @@ -84,13 +84,13 @@ context "as an array" do it "should instanciate an api line object" do line = Collmex::Api::Login.new([12,34]).to_a - described_class.parse_line(line).should be_a Collmex::Api::Line + expect(described_class.parse_line(line)).to be_a Collmex::Api::Line end end context "as n csv string" do it "should instanciate an api line object" do line = Collmex::Api::Login.new([12,34]).to_csv - described_class.parse_line(line).should be_a Collmex::Api::Line + expect(described_class.parse_line(line)).to be_a Collmex::Api::Line end end end @@ -98,7 +98,7 @@ context "when given an invalid line" do it "should throw an error" do line = ["OMG", 2,3,4,5,6] - lambda { described_class.parse_line(line) }.should raise_error 'Could not find a Collmex::Api::Line class for "Omg" ("OMG")' + expect { described_class.parse_line(line) }.to raise_error 'Could not find a Collmex::Api::Line class for "Omg" ("OMG")' end end end @@ -173,7 +173,7 @@ ] tests.each_with_index do |t,i| it "should parse #{t[:type]} value for \"#{t[:input]}\"" do - described_class.parse_field( t[:input], t[:type]).should === t[:outcome] + expect(described_class.parse_field( t[:input], t[:type])).to be === t[:outcome] end end end @@ -192,12 +192,12 @@ output = { identifyer: string, b: currency, c: float, d: integer, e: Date.parse("12.10.1985") } - described_class.stub(:specification).and_return(sample_spec) - Collmex::Api.stub(:parse_field).with(anything(),:string).and_return string - Collmex::Api.stub(:parse_field).with(anything(),:float).and_return float - Collmex::Api.stub(:parse_field).with(anything(),:integer).and_return integer - Collmex::Api.stub(:parse_field).with(anything(),:currency).and_return currency - Collmex::Api.stub(:parse_field).with(anything(),:date).and_return date + allow(described_class).to receive(:specification).and_return(sample_spec) + allow(Collmex::Api).to receive(:parse_field).with(anything(),:string).and_return string + allow(Collmex::Api).to receive(:parse_field).with(anything(),:float).and_return float + allow(Collmex::Api).to receive(:parse_field).with(anything(),:integer).and_return integer + allow(Collmex::Api).to receive(:parse_field).with(anything(),:currency).and_return currency + allow(Collmex::Api).to receive(:parse_field).with(anything(),:date).and_return date tests = [ [1,2,3,4], @@ -213,7 +213,7 @@ ] tests.each do |testdata| - described_class.hashify(testdata).should eql output + expect(described_class.hashify(testdata)).to eql output end end @@ -225,8 +225,8 @@ { name: :d, type: :float, default: 2.99 }, ] sample_default_outcome = {a: "fixvalue", b: 899, c: 10, d: 2.99} - described_class.stub(:specification).and_return sample_default_spec - described_class.hashify([]).should eql sample_default_outcome + allow(described_class).to receive(:specification).and_return sample_default_spec + expect(described_class.hashify([])).to eql sample_default_outcome end it "should overwrite default values when data is given" do @@ -237,8 +237,8 @@ { name: :d, type: :float, default: 2.99 }, ] sample_default_outcome = {a: "asd", b: 12, c: 1, d: 1.0} - described_class.stub(:specification).and_return sample_default_spec - described_class.hashify({a: "asd", b: 12, c: 1, d: 1}).should eql sample_default_outcome + allow(described_class).to receive(:specification).and_return sample_default_spec + expect(described_class.hashify({a: "asd", b: 12, c: 1, d: 1})).to eql sample_default_outcome end it "should ignore given values for fix-value-fields" do @@ -249,47 +249,47 @@ { name: :d, type: :float, fix: 2.99 }, ] sample_fix_outcome = {a: "fixvalue", b: 899, c: 10, d: 2.99} - described_class.stub(:specification).and_return sample_fix_spec - described_class.hashify([]).should eql sample_fix_outcome + allow(described_class).to receive(:specification).and_return sample_fix_spec + expect(described_class.hashify([])).to eql sample_fix_outcome end end describe ".default_hash" do it "should hold a specification" do - described_class.stub(:specification).and_return([]) - described_class.default_hash.should eql({}) + allow(described_class).to receive(:specification).and_return([]) + expect(described_class.default_hash).to eql({}) - described_class.stub(:specification).and_return(sample_spec) - described_class.default_hash.should eql(empty_hash) + allow(described_class).to receive(:specification).and_return(sample_spec) + expect(described_class.default_hash).to eql(empty_hash) end end subject { described_class.new } - it { should respond_to :to_csv } - it { should respond_to :to_a } - it { should respond_to :to_s } - it { should respond_to :to_h } + it { is_expected.to respond_to :to_csv } + it { is_expected.to respond_to :to_a } + it { is_expected.to respond_to :to_s } + it { is_expected.to respond_to :to_h } describe "#initialize" do it "should raise an error if the specification is empty and the class is not Collmex::Api::Line" do - described_class.stub(:specification).and_return({}) + allow(described_class).to receive(:specification).and_return({}) if described_class.name == "Collmex::Api::Line" - lambda { described_class.new }.should_not raise_error + expect { described_class.new }.not_to raise_error else - lambda { described_class.new }.should raise_error "#{described_class.name} has no specification" + expect { described_class.new }.to raise_error "#{described_class.name} has no specification" end end it "should set the instance_variable hash" do - subject.instance_variable_get(:@hash).should be_a Hash + expect(subject.instance_variable_get(:@hash)).to be_a Hash end context "no params given" do it "should build the specified but empty hash" do - described_class.stub(:default_hash).and_return(empty_hash) + allow(described_class).to receive(:default_hash).and_return(empty_hash) line = described_class.new - line.to_h.should eql(empty_hash) + expect(line.to_h).to eql(empty_hash) end end @@ -298,19 +298,19 @@ input = {:a => "bla" } output = empty_hash.merge(input) - described_class.stub(:default_hash).and_return(empty_hash) - described_class.stub(:hashify).and_return(output) + allow(described_class).to receive(:default_hash).and_return(empty_hash) + allow(described_class).to receive(:hashify).and_return(output) line = described_class.new(input) - line.to_h.should eql (output) + expect(line.to_h).to eql (output) end end end describe "#to_csv" do it "should represent the request as csv" do - described_class.stub(:specification).and_return(sample_spec) + allow(described_class).to receive(:specification).and_return(sample_spec) subject.instance_variable_set(:@hash, described_class.hashify(filled_array)) - subject.to_csv.should eql filled_csv + expect(subject.to_csv).to eql filled_csv end end @@ -318,14 +318,14 @@ it "should return the hash" do h = { first: 1, second: 2 } subject.instance_variable_set(:@hash, h) - subject.to_h.should eql h + expect(subject.to_h).to eql h end end describe "#to_a" do it "should return the empty_hash translated to an array" do - described_class.stub(:specification).and_return(sample_spec) - subject.to_a.should eql empty_array + allow(described_class).to receive(:specification).and_return(sample_spec) + expect(subject.to_a).to eql empty_array end end @@ -346,10 +346,10 @@ { name: :password, type: :string } ] - specify { described_class.specification.should eql spec } + specify { expect(described_class.specification).to eql spec } output = ["LOGIN", "012", "34"] - specify { subject.to_a.should eql output } + specify { expect(subject.to_a).to eql output } end describe Collmex::Api::CustomerGet do @@ -372,13 +372,13 @@ { name: :inactive , type: :integer }, ] - specify { described_class.specification.should eql spec } + specify { expect(described_class.specification).to eql spec } subject { described_class.new( {:customer_id => 9999} ) } output = ["CUSTOMER_GET", nil, 1, "", nil, "", nil, nil, nil, nil, nil, "", nil] - specify { subject.to_a.should eql output } + specify { expect(subject.to_a).to eql output } end describe Collmex::Api::AccdocGet do @@ -407,13 +407,13 @@ - specify { described_class.specification.should eql spec } + specify { expect(described_class.specification).to eql spec } subject { described_class.new( {id: 1} ) } output = ["ACCDOC_GET", 1, nil, 1, nil, nil, nil, nil, nil, nil, nil, "", nil, nil, nil, nil, ""] - specify { subject.to_a.should eql output } + specify { expect(subject.to_a).to eql output } end describe Collmex::Api::AccbalGet do @@ -429,13 +429,13 @@ {name: :account_group, type: :integer} ] - specify { described_class.specification.should eql spec } + specify { expect(described_class.specification).to eql spec } subject { described_class.new( {id: 1} ) } output = ["ACCBAL_GET", 1, Date.today.year, nil, nil, nil] - specify { subject.to_a.should eql output } + specify { expect(subject.to_a).to eql output } end @@ -488,15 +488,18 @@ { name: :output_language , type: :integer }, { name: :email_cc , type: :string }, { name: :phone_2 , type: :string }, + { name: :sepa_mandate_reference, type: :string }, + { name: :sepa_mandate_signature_date, type: :date }, + { name: :dunning_block , type: :integer }, ] - specify { described_class.specification.should eql spec } + specify { expect(described_class.specification).to eql spec } subject { described_class.new( {id: 1} ) } - output = ["CMXKND", nil, 1, "", "", "", "", "", "", "", "", "", "", nil, "", "", "", "", "", "", "", "", "", "", "", nil, nil, "", "", nil, "", nil, "", nil, "", nil, "", nil, nil, nil, "", nil, "", ""] + output = ["CMXKND", nil, 1, "", "", "", "", "", "", "", "", "", "", nil, "", "", "", "", "", "", "", "", "", "", "", nil, nil, "", "", nil, "", nil, "", nil, "", nil, "", nil, nil, nil, "", nil, "", "", "", nil, nil] - specify { subject.to_a.should eql output } + specify { expect(subject.to_a).to eql output } end @@ -513,43 +516,43 @@ { name: :line , type: :integer }, ] - specify { described_class.specification.should eql spec } + specify { expect(described_class.specification).to eql spec } subject { described_class.new( ) } output = ["MESSAGE", "", nil, "", nil] - specify { subject.to_a.should eql output } + specify { expect(subject.to_a).to eql output } context "success" do subject { described_class.new(type: "S") } specify do - subject.success?.should eql true - subject.result.should eql :success + expect(subject.success?).to eql true + expect(subject.result).to eql :success end end context "warning" do subject { described_class.new(type: "W") } specify do - subject.success?.should eql false - subject.result.should eql :warning + expect(subject.success?).to eql false + expect(subject.result).to eql :warning end end context "error" do subject { described_class.new(type: "E") } specify do - subject.success?.should eql false - subject.result.should eql :error + expect(subject.success?).to eql false + expect(subject.result).to eql :error end end context "undefined" do subject { described_class.new() } specify do - subject.success?.should eql false - subject.result.should eql :undefined + expect(subject.success?).to eql false + expect(subject.result).to eql :undefined end end @@ -593,13 +596,13 @@ - specify { described_class.specification.should eql spec } + specify { expect(described_class.specification).to eql spec } subject { described_class.new( {id: 1} ) } output = ["ACCDOC", 1, nil, 1, nil, nil, "", nil, nil, "", nil, nil, nil, "", nil, "", nil, "", nil, "", "", nil, nil, nil, nil, nil] - specify { subject.to_a.should eql output } + specify { expect(subject.to_a).to eql output } end @@ -615,12 +618,55 @@ {name: :account_balance, type: :currency} ] - specify { described_class.specification.should eql spec } + specify { expect(described_class.specification).to eql spec } subject { described_class.new( {id: 1} ) } output = ["ACC_BAL", nil, "", nil] - specify { subject.to_a.should eql output } + specify { expect(subject.to_a).to eql output } end +describe Collmex::Api::Cmxums do + + it_behaves_like "Collmex Api Command" + spec = + [ + { name: :_1_identifyer, type: :string, fix: "CMXUMS"}, # 1 + { name: :_2_customer_id, type: :integer}, + { name: :_3_company_id, type: :integer, default: 1}, + { name: :_4_receipt_date, type: :date }, + { name: :_5_receipt_number, type: :string }, # 5 + { name: :_6_net_value_full_tax, type: :currency }, + { name: :_7_tax_value_full_tax, type: :currency }, + { name: :_8_net_value_half_tax, type: :currency }, + { name: :_9_tax_value_half_tax, type: :currency }, + { name: :_10_net_value_inter_eu_trade, type: :currency }, # 10 + { name: :_11_net_value_export, type: :currency }, + { name: :_12_account_revenue_tax_free, type: :integer }, + { name: :_13_value_revenue_tax_free, type: :currency }, + { name: :_14_currency_code, type: :string }, + { name: :_15_contra_account, type: :integer }, # 15 + { name: :_16_receipt_type, type: :integer, default: 0 }, + { name: :_17_receipt_text, type: :string }, + { name: :_18_payment_term, type: :integer }, + { name: :_19_account_full_tax, type: :integer }, + { name: :_20_account_half_tax, type: :integer }, # 20 + { name: :_21_reserved21, type: :string }, + { name: :_22_reserved22, type: :string }, + { name: :_23_storno, type: :integer }, + { name: :_24_final_receipt, type: :string }, + { name: :_25_revenue_type, type: :integer }, # 25 + { name: :_26_system_name, type: :string }, + { name: :_27_charge_against_receipt_number, type: :string }, + { name: :_28_cost_center, type: :string } + ] + + specify { expect(described_class.specification).to eql spec } + + subject { described_class.new( {id: 1} ) } + + output = ["CMXUMS", nil, 1, nil, "", nil, nil, nil, nil, nil, nil, nil, nil, "", nil, 0, "", nil, nil, nil, "", "", nil, "", nil, "", "", ""] + + specify { expect(subject.to_a).to eql output } +end diff --git a/spec/lib/collmex/request_spec.rb b/spec/lib/collmex/request_spec.rb index 43cb348..4dd02df 100644 --- a/spec/lib/collmex/request_spec.rb +++ b/spec/lib/collmex/request_spec.rb @@ -4,13 +4,13 @@ describe ".run" do it "should return an instance of Colmex::Request" do - Collmex::Request.any_instance.stub(:execute) - Collmex::Request.run.should be_a Collmex::Request + allow_any_instance_of(Collmex::Request).to receive(:execute) + expect(Collmex::Request.run).to be_a Collmex::Request end it "should execute a given block" do - Collmex::Request.any_instance.stub(:execute) - Collmex::Request.any_instance.should_receive(:dump).with("arr").and_return("blaaaa") + allow_any_instance_of(Collmex::Request).to receive(:execute) + expect_any_instance_of(Collmex::Request).to receive(:dump).with("arr").and_return("blaaaa") Collmex::Request.run do dump "arr" end @@ -19,11 +19,11 @@ describe ".uri" do subject { Collmex::Request.uri } - specify { subject.to_s.should eql "https://www.collmex.de/cgi-bin/cgi.exe?#{Collmex.customer_id},0,data_exchange" } + specify { expect(subject.to_s).to eql "https://www.collmex.de/cgi-bin/cgi.exe?#{Collmex.customer_id},0,data_exchange" } end subject { described_class.new } - specify { subject.should be_a Collmex::Request } + specify { expect(subject).to be_a Collmex::Request } @@ -31,12 +31,12 @@ it "should raise an error if no credentials given" do Collmex.reset_login_data - lambda { Collmex::Request.new }.should raise_error "No credentials for collmex given" + expect { Collmex::Request.new }.to raise_error "No credentials for collmex given" end it "should add the Login command to its own queue" do request = Collmex::Request.new - request.commands.count.should eql 1 + expect(request.commands.count).to eql 1 end end @@ -44,11 +44,11 @@ it "should add the given command to its command array" do request = Collmex::Request.new - request.should be_a Collmex::Request + expect(request).to be_a Collmex::Request request.commands = Array.new request.add_command "asd" - request.commands.count.should eql 1 + expect(request.commands.count).to eql 1 end end @@ -57,8 +57,8 @@ subject { Collmex::Request } specify do - subject.classify(:accdoc_get).should eql "AccdocGet" - subject.classify(:accDoc_get).should eql "AccdocGet" + expect(subject.classify(:accdoc_get)).to eql "AccdocGet" + expect(subject.classify(:accDoc_get)).to eql "AccdocGet" end end @@ -68,14 +68,14 @@ let(:request) { Collmex::Request.new } it "should return a command object" do - request.enqueue(:accdoc_get).should be_a Collmex::Api::AccdocGet + expect(request.enqueue(:accdoc_get)).to be_a Collmex::Api::AccdocGet end it "should enqueue the given comands" do initial_count = request.commands.count request.enqueue :accdoc_get request.enqueue :accdoc_get, :accdoc_id => 1 - request.commands.count.should equal (initial_count + 2) + expect(request.commands.count).to equal (initial_count + 2) end end @@ -85,15 +85,15 @@ it "should retun the command object" do cmd_obj = Collmex::Api::AccdocGet.new() - request.enqueue(cmd_obj).should eql cmd_obj + expect(request.enqueue(cmd_obj)).to eql cmd_obj end it "should enqueue the command object" do initial_count = request.commands.count cmd_obj = Collmex::Api::AccdocGet.new() request.enqueue cmd_obj - request.commands.count.should eql (initial_count + 1) - request.commands.last.should eql cmd_obj + expect(request.commands.count).to eql (initial_count + 1) + expect(request.commands.last).to eql cmd_obj end end @@ -103,59 +103,59 @@ describe ".execute" do before(:each) do - Net::HTTP.stub(:new).and_return(http) - Net::HTTP.stub(:request_post).and_return(response) - Collmex::Api.stub(:parse_line) + allow(Net::HTTP).to receive(:new).and_return(http) + allow(Net::HTTP).to receive(:request_post).and_return(response) + allow(Collmex::Api).to receive(:parse_line) end let(:http) do http = double(Net::HTTP) - http.stub("use_ssl=") - http.stub("verify_mode=") - http.stub(:request_post).and_return(response) + allow(http).to receive("use_ssl=") + allow(http).to receive("verify_mode=") + allow(http).to receive(:request_post).and_return(response) http end let(:response) do response = double(Net::HTTPOK) - response.stub(:body).and_return("fuckmehard") - response.stub(:code).and_return(200) + allow(response).to receive(:body).and_return("fuckmehard") + allow(response).to receive(:code).and_return(200) response end it "should create an instance of net::http" do - Net::HTTP.should_receive(:new).and_return(http) + expect(Net::HTTP).to receive(:new).and_return(http) subject.execute end it "should use ssl" do - http.should_receive("use_ssl=").with(true) + expect(http).to receive("use_ssl=").with(true) subject.execute end it "should not verify ssl" do - http.should_receive("verify_mode=").with(OpenSSL::SSL::VERIFY_NONE) + expect(http).to receive("verify_mode=").with(OpenSSL::SSL::VERIFY_NONE) subject.execute end it "shoud do the post_request" do - http.should_receive(:request_post).with(anything,anything,{"Content-Type" => "text/csv"}).and_return(response) + expect(http).to receive(:request_post).with(anything,anything,{"Content-Type" => "text/csv"}).and_return(response) subject.execute end context "with a working connection" do it "should parse the response" do - subject.stub(:parse_response).and_return( [Collmex::Api::Accdoc.new]) - subject.should_receive(:parse_response) + allow(subject).to receive(:parse_response).and_return( [Collmex::Api::Accdoc.new]) + expect(subject).to receive(:parse_response) subject.execute end it "the response should be encoded in utf-8" do string = "Allgemeiner Gesch\xE4ftspartne".force_encoding("ASCII-8BIT") - response.stub(:body).and_return(string) + allow(response).to receive(:body).and_return(string) subject.execute - subject.instance_variable_get(:@raw_response)[:string].encoding.to_s.should eql "UTF-8" + expect(subject.instance_variable_get(:@raw_response)[:string].encoding.to_s).to eql "UTF-8" end end diff --git a/spec/lib/collmex_spec.rb b/spec/lib/collmex_spec.rb index 0725bb8..5197c83 100644 --- a/spec/lib/collmex_spec.rb +++ b/spec/lib/collmex_spec.rb @@ -6,9 +6,9 @@ describe Collmex do - it {should respond_to :username} - it {should respond_to :password} - it {should respond_to :customer_id} + it {is_expected.to respond_to :username} + it {is_expected.to respond_to :password} + it {is_expected.to respond_to :customer_id} end @@ -38,7 +38,7 @@ end VCR.use_cassette('standard_request') do - request.response.last.success?.should eql true + expect(request.response.last.success?).to eql true end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6c982bd..4cd7ed7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,10 +5,9 @@ Coveralls.wear! RSpec.configure do |config| - config.color_enabled = true + config.color = true config.filter_run :focus => true config.run_all_when_everything_filtered = true - config.treat_symbols_as_metadata_keys_with_true_values = true config.before(:each) do Collmex.setup_login_data({username: "8866413", password: "2291502", customer_id: "104156"})