1
0
mirror of https://github.com/danbee/micropub.git synced 2025-03-04 08:59:13 +00:00

First couple of request specs

Added Mocha because standard minitest mocking/stubbing kinda sucks.
This commit is contained in:
Daniel Barber 2019-11-16 16:05:26 -05:00
parent db76e98305
commit 20b68453dd
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
9 changed files with 127 additions and 1 deletions

View File

@ -14,4 +14,8 @@ gem "github_api"
gem "indieweb-endpoints"
gem "pry"
gem "minitest"
gem "minitest-hooks"
gem "mocha"
gem "rack-test"

View File

@ -6,6 +6,7 @@ GEM
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
backports (3.15.0)
coderay (1.1.2)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
domain_name (0.5.20190701)
@ -43,8 +44,14 @@ GEM
jwt (2.2.1)
link-header-parser (0.2.0)
absolutely (~> 3.0)
metaclass (0.0.4)
method_source (0.9.2)
mini_portile2 (2.4.0)
minitest (5.13.0)
minitest-hooks (1.5.0)
minitest (> 5.3)
mocha (1.9.0)
metaclass (~> 0.0.1)
multi_json (1.14.1)
multi_xml (0.6.0)
multipart-post (2.1.1)
@ -58,12 +65,17 @@ GEM
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (>= 1.2, < 3)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
public_suffix (4.0.1)
puma (4.2.1)
nio4r (~> 2.0)
rack (2.0.7)
rack-protection (2.0.7)
rack
rack-test (1.1.0)
rack (>= 1.0, < 3)
rake (13.0.0)
sinatra (2.0.7)
mustermann (~> 1.0)
@ -92,7 +104,11 @@ DEPENDENCIES
github_api
indieweb-endpoints
minitest
minitest-hooks
mocha
pry
puma
rack-test
sinatra
sinatra-contrib

29
bin/coderay Executable file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
#
# This file was generated by Bundler.
#
# The application 'coderay' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
bundle_binstub = File.expand_path("../bundle", __FILE__)
if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end
require "rubygems"
require "bundler/setup"
load Gem.bin_path("coderay", "coderay")

29
bin/pry Executable file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
#
# This file was generated by Bundler.
#
# The application 'pry' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
bundle_binstub = File.expand_path("../bundle", __FILE__)
if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end
require "rubygems"
require "bundler/setup"
load Gem.bin_path("pry", "pry")

View File

@ -3,7 +3,6 @@ require 'sinatra/contrib'
module Micropub
class Webserver < Sinatra::Base
register Sinatra::ConfigFile
register Sinatra::Namespace
set server: 'puma'

11
test/request_helper.rb Normal file
View File

@ -0,0 +1,11 @@
require "test_helper"
require 'minitest/hooks'
include Rack::Test::Methods
MiniTest::Spec.register_spec_type(/something/, Minitest::HooksSpec)
def app
Micropub::Webserver
end
ENV["SITE_URL"] = "https://test.danbarber.me"

View File

@ -0,0 +1,19 @@
require "request_helper"
require "micropub/indieauth"
require "micropub/github"
describe "create post" do
it "creates a simple post" do
Micropub::Webserver.any_instance.stubs(:valid_token?).returns(true)
Micropub::Github.any_instance.stubs(:post!).returns(true)
post '/micropub/main', {
content: "Hello, World!"
}
date = Time.now.strftime("%Y/%m/%d")
assert last_response.accepted?
assert_equal last_response.headers["Location"],
"https://test.danbarber.me/blog/#{date}/hello-world"
end
end

View File

@ -0,0 +1,15 @@
require "test_helper"
class HelloWorldTest < MiniTest::Unit::TestCase
include Rack::Test::Methods
def app
Micropub::Webserver
end
def test_hello_world
get '/'
assert last_response.ok?
assert_equal "Hello, World!", last_response.body
end
end

View File

@ -1,4 +1,8 @@
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
require "micropub"
require "rack/test"
require "minitest/autorun"
require "mocha/minitest"
require "pry"