require File.expand_path(File.dirname(__FILE__) + "/../spec_helper") describe Cardflex::BaseModule do class TestClass include Cardflex::BaseModule module Type A = 'a' B = 'b' C = 'c' end def initialize(attrs) set_instance_variables_from_hash(attrs) end end it 'should assign instance variables from a hash' do TestClass.set_instance_variables_from_hash({ :test => 'value' }) expect(TestClass.instance_variables).to include :@test expect(TestClass.instance_variable_get("@test")).to eq 'value' end it 'should preserve nested hashes' do TestClass.set_instance_variables_from_hash({ :test => { :nest => 'nested' }}) expect(TestClass.instance_variable_get("@test")).to eq({ :nest => 'nested' }) end it 'should snake case a string' do expect(TestClass.snakecase('dash-case-variable')).to eq('dash_case_variable') end it 'should create helper methods' do TestClass.__send__(:create_helper_methods, TestClass::Type) expect(TestClass.methods).to include(:a, :b, :c) end it 'should have merchant defined fields available' do sut = TestClass.new(:merchant_defined_field_1 => 'test') expect(sut.merchant_defined_field_1).to eq 'test' end it 'should raise an undefined method error for non existent merchant field' do expect { TestClass.new.merchant_defined_field_1 }.to raise_error end end