Sha256: ee9e2f0e4115d75c41e2b2dde7c5abee19580904cff5241208cb94f88ea4db84

Contents?: true

Size: 1.73 KB

Versions: 3

Compression:

Stored size: 1.73 KB

Contents

require 'spec_helper'

module Gram
  describe Blog do

    before do
      File.stub(:exists?).and_return true
    end
   
    describe ".upload" do
      it 'parses the file' do
        subject::Parser.should_receive(:parse).with("my_post.md")
        expect {
          subject.upload("my_post.md")
        }.to raise_error(RestClient::InternalServerError)
      end
      it 'sends a post request' do
        post = double :post
        token = double :token
        response = double :response, code: 201, body: 'ok'
        subject.stub(:get_token).and_return token
        subject::Parser.stub(:parse).with("my_post.md").and_return post

        RestClient.should_receive(:post).with("http://codegram.com/api/posts", token: token, post: post).and_return response

        subject.upload("my_post.md")
      end
    end

    describe ".download" do
      it 'gets the posts' do
        RestClient.stub(:get)
        JSON.should_receive(:parse).and_return [ { "post" => {
                                                      "title"   => "My title",
                                                      "tagline" => "My tagline",
                                                      "cached_slug" => "my-post",
                                                      "body" => "#Hello world"
                                                  } } ]

        file = double(:file)
        File.should_receive(:open).with('my-post.markdown', 'w').and_yield file
        file.should_receive(:write).with """
---
title: My title
tagline: My tagline
---
        """.strip
        file.should_receive(:write).with "\n\n"
        file.should_receive(:write).with "#Hello world"
        file.should_receive(:write).with "\n"

        subject.download
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gram-0.3.0 spec/gram/blog_spec.rb
gram-0.2.0 spec/gram/blog_spec.rb
gram-0.1.0 spec/gram/blog_spec.rb