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:
parent
db76e98305
commit
20b68453dd
4
Gemfile
4
Gemfile
@ -14,4 +14,8 @@ gem "github_api"
|
|||||||
|
|
||||||
gem "indieweb-endpoints"
|
gem "indieweb-endpoints"
|
||||||
|
|
||||||
|
gem "pry"
|
||||||
gem "minitest"
|
gem "minitest"
|
||||||
|
gem "minitest-hooks"
|
||||||
|
gem "mocha"
|
||||||
|
gem "rack-test"
|
||||||
|
|||||||
16
Gemfile.lock
16
Gemfile.lock
@ -6,6 +6,7 @@ GEM
|
|||||||
addressable (2.7.0)
|
addressable (2.7.0)
|
||||||
public_suffix (>= 2.0.2, < 5.0)
|
public_suffix (>= 2.0.2, < 5.0)
|
||||||
backports (3.15.0)
|
backports (3.15.0)
|
||||||
|
coderay (1.1.2)
|
||||||
descendants_tracker (0.0.4)
|
descendants_tracker (0.0.4)
|
||||||
thread_safe (~> 0.3, >= 0.3.1)
|
thread_safe (~> 0.3, >= 0.3.1)
|
||||||
domain_name (0.5.20190701)
|
domain_name (0.5.20190701)
|
||||||
@ -43,8 +44,14 @@ GEM
|
|||||||
jwt (2.2.1)
|
jwt (2.2.1)
|
||||||
link-header-parser (0.2.0)
|
link-header-parser (0.2.0)
|
||||||
absolutely (~> 3.0)
|
absolutely (~> 3.0)
|
||||||
|
metaclass (0.0.4)
|
||||||
|
method_source (0.9.2)
|
||||||
mini_portile2 (2.4.0)
|
mini_portile2 (2.4.0)
|
||||||
minitest (5.13.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_json (1.14.1)
|
||||||
multi_xml (0.6.0)
|
multi_xml (0.6.0)
|
||||||
multipart-post (2.1.1)
|
multipart-post (2.1.1)
|
||||||
@ -58,12 +65,17 @@ GEM
|
|||||||
multi_json (~> 1.3)
|
multi_json (~> 1.3)
|
||||||
multi_xml (~> 0.5)
|
multi_xml (~> 0.5)
|
||||||
rack (>= 1.2, < 3)
|
rack (>= 1.2, < 3)
|
||||||
|
pry (0.12.2)
|
||||||
|
coderay (~> 1.1.0)
|
||||||
|
method_source (~> 0.9.0)
|
||||||
public_suffix (4.0.1)
|
public_suffix (4.0.1)
|
||||||
puma (4.2.1)
|
puma (4.2.1)
|
||||||
nio4r (~> 2.0)
|
nio4r (~> 2.0)
|
||||||
rack (2.0.7)
|
rack (2.0.7)
|
||||||
rack-protection (2.0.7)
|
rack-protection (2.0.7)
|
||||||
rack
|
rack
|
||||||
|
rack-test (1.1.0)
|
||||||
|
rack (>= 1.0, < 3)
|
||||||
rake (13.0.0)
|
rake (13.0.0)
|
||||||
sinatra (2.0.7)
|
sinatra (2.0.7)
|
||||||
mustermann (~> 1.0)
|
mustermann (~> 1.0)
|
||||||
@ -92,7 +104,11 @@ DEPENDENCIES
|
|||||||
github_api
|
github_api
|
||||||
indieweb-endpoints
|
indieweb-endpoints
|
||||||
minitest
|
minitest
|
||||||
|
minitest-hooks
|
||||||
|
mocha
|
||||||
|
pry
|
||||||
puma
|
puma
|
||||||
|
rack-test
|
||||||
sinatra
|
sinatra
|
||||||
sinatra-contrib
|
sinatra-contrib
|
||||||
|
|
||||||
|
|||||||
29
bin/coderay
Executable file
29
bin/coderay
Executable 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
29
bin/pry
Executable 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")
|
||||||
@ -3,7 +3,6 @@ require 'sinatra/contrib'
|
|||||||
|
|
||||||
module Micropub
|
module Micropub
|
||||||
class Webserver < Sinatra::Base
|
class Webserver < Sinatra::Base
|
||||||
register Sinatra::ConfigFile
|
|
||||||
register Sinatra::Namespace
|
register Sinatra::Namespace
|
||||||
|
|
||||||
set server: 'puma'
|
set server: 'puma'
|
||||||
|
|||||||
11
test/request_helper.rb
Normal file
11
test/request_helper.rb
Normal 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"
|
||||||
19
test/requests/create_post_test.rb
Normal file
19
test/requests/create_post_test.rb
Normal 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
|
||||||
15
test/requests/hello_world_test.rb
Normal file
15
test/requests/hello_world_test.rb
Normal 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
|
||||||
@ -1,4 +1,8 @@
|
|||||||
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
|
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
|
||||||
require "micropub"
|
require "micropub"
|
||||||
|
|
||||||
|
require "rack/test"
|
||||||
require "minitest/autorun"
|
require "minitest/autorun"
|
||||||
|
require "mocha/minitest"
|
||||||
|
|
||||||
|
require "pry"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user