Sha256: 20833bfa976863762256410a50618e83c7c63c17b78c9fa787d02e6db64be410

Contents?: true

Size: 1.3 KB

Versions: 9

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

require 'spec_helper'
require 'slack_messaging'

describe SlackMessaging::RandomMessage do
  let(:quote_object) { double(:quote_object, body: quote_json) }

  let(:quote_json) do
    "{\"_id\":\"4MRaRRKq4Tcg\",
      \"tags\":[\"famous-quotes\"],
      \"content\":\"There are two ways of spreading light: to be the candle or the mirror that reflects it.\",
      \"author\":\"Edith Wharton\",\"length\":87
    }"
  end

  before do
    allow(HTTParty).to receive(:get).and_return(quote_object)
  end

  subject { SlackMessaging::RandomMessage }

  it 'should get a string message' do
    message = subject.acquire_random_quote
    expect(message).to be_instance_of(String)
  end

  it 'should get a message that includes a newline' do
    message = subject.acquire_random_quote
    expect(message.include?("\n")).to eq(true)
  end

  it 'should get a message that includes a —' do
    message = subject.acquire_random_quote
    expect(message.include?('—')).to eq(true)
  end

  it 'should use HTTParty to ping an API' do
    expect(HTTParty).to receive(:get)
    subject.acquire_random_quote
  end

  it 'should have the JSON parse the response content twice' do
    expect(JSON).to receive(:parse).at_least(2).times.and_return(JSON.parse(quote_json))
    subject.acquire_random_quote
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
slack_messaging-3.2.3 spec/slack_messaging/random_message_spec.rb
slack_messaging-3.2.2 spec/slack_messaging/random_message_spec.rb
slack_messaging-3.2.1 spec/slack_messaging/random_message_spec.rb
slack_messaging-3.2.0 spec/slack_messaging/random_message_spec.rb
slack_messaging-3.1.3 spec/slack_messaging/random_message_spec.rb
slack_messaging-3.1.2 spec/slack_messaging/random_message_spec.rb
slack_messaging-3.1.1 spec/slack_messaging/random_message_spec.rb
slack_messaging-3.1.0 spec/slack_messaging/random_message_spec.rb
slack_messaging-3.0.0 spec/slack_messaging/random_message_spec.rb