Module: Ey::Core::TestHelpers::ClientHelpers
- Included in:
- Ey::Core::TestHelpers
- Defined in:
- lib/ey-core/test_helpers/client_helpers.rb
Instance Method Summary collapse
- #create_client(attributes = {}) ⇒ Object
- #create_server_client(server, attributes = {}) ⇒ Object
- #create_unauthenticated_client ⇒ Object
Instance Method Details
#create_client(attributes = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ey-core/test_helpers/client_helpers.rb', line 5 def create_client(attributes={}) token = if (user = attributes.delete(:user)) && Ey::Core::Client.mocking? core = Ey::Core::Client::Mock.data.values.find { |c| c[:users][user.identity] } core[:users][user.identity]["token"] end token ||= begin token_dotfile = YAML.load_file(File.("/../../../.token"), __FILE__) rescue {} ENV["CORE_TOKEN"] || token_dotfile[ENV["CORE_URL"]] || "a4bf6558da8c1051536d1596b8931ebd346aff0b" end merged_attributes = attributes.merge(token: token, cache: true) merged_attributes.merge!(logger: Logger.new(STDOUT)) if ENV['VERBOSE'] Ey::Core::Client.new(merged_attributes) end |
#create_server_client(server, attributes = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ey-core/test_helpers/client_helpers.rb', line 21 def create_server_client(server, attributes={}) unless core = Ey::Core::Client::Mock.data.values.find { |data| data[:servers][server.identity] } raise "Failed to find server in mock data: #{server}" end token = core[:servers][server.identity]["token"] merged_attributes = attributes.merge(token: token, cache: true) merged_attributes.merge!(logger: Logger.new(STDOUT)) if ENV['VERBOSE'] Ey::Core::Client.new(merged_attributes) end |