Sha256: 8b0741bd9fe67766ba5a3f8eff0521f50189816618c630bae59b5b5004e4481e

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

require './lib/commands/new_command'
require './lib/commands/tweet_command'
require 'fakefs/spec_helpers'
require 'timecop'

RSpec.describe TweetCommand do
  describe '#execute' do
    include FakeFS::SpecHelpers

    let(:command) { TweetCommand.new('testdir') }
    let(:tweet) { 'this is a tweet' }
    let(:tweet_id) { '525483671584002048' }
    let(:tweet_url) { "https://twitter.com/amoschan/status/#{tweet_id}" }
    let(:tweet_post) do
<<-TWEET
---
title: tweet #{tweet_id}
timestamp: #{now}
layout: tweet
tweet: #{tweet_url}
---

this is a tweet
TWEET
    end

    let(:now) { DateTime.now }

    let(:created_tweet) do
      double()
    end

    before do
      created_tweet.stub(:uri).and_return(URI(tweet_url))
      created_tweet.stub(:id).and_return(tweet_id)
      allow_any_instance_of(AppConfig).
          to receive(:vars).and_return({
        'twitter' => { 'access_token' => 'token',
                       'access_token_secret' => 'secret' }
      })

      expect_any_instance_of(Twitter::REST::Client).
          to receive(:update).with(tweet).and_return(created_tweet)

      Timecop.freeze do
        NewCommand.new('testdir').execute
        Dir.chdir('testdir')
        TweetCommand.new('this is a tweet').execute
        now
      end
    end

    it 'creates new tweet' do
      File.open("_posts/tweet-#{tweet_id}.md", 'r') do |file|
        expect(file.read()).to eq(tweet_post)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ignoramos-1.0.1 spec/commands/tweet_command_spec.rb
ignoramos-1.0.0 spec/commands/tweet_command_spec.rb