diff --git a/Gemfile b/Gemfile index 117fdb0..7dee6cd 100644 --- a/Gemfile +++ b/Gemfile @@ -14,4 +14,8 @@ gem "github_api" gem "indieweb-endpoints" +gem "pry" gem "minitest" +gem "minitest-hooks" +gem "mocha" +gem "rack-test" diff --git a/Gemfile.lock b/Gemfile.lock index 1920fd9..099bac6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/bin/coderay b/bin/coderay new file mode 100755 index 0000000..f08e818 --- /dev/null +++ b/bin/coderay @@ -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") diff --git a/bin/pry b/bin/pry new file mode 100755 index 0000000..bfcc3d4 --- /dev/null +++ b/bin/pry @@ -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") diff --git a/lib/micropub/webserver.rb b/lib/micropub/webserver.rb index dfd188d..1cf6004 100644 --- a/lib/micropub/webserver.rb +++ b/lib/micropub/webserver.rb @@ -3,7 +3,6 @@ require 'sinatra/contrib' module Micropub class Webserver < Sinatra::Base - register Sinatra::ConfigFile register Sinatra::Namespace set server: 'puma' diff --git a/test/request_helper.rb b/test/request_helper.rb new file mode 100644 index 0000000..ef26ab8 --- /dev/null +++ b/test/request_helper.rb @@ -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" diff --git a/test/requests/create_post_test.rb b/test/requests/create_post_test.rb new file mode 100644 index 0000000..53f7040 --- /dev/null +++ b/test/requests/create_post_test.rb @@ -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 diff --git a/test/requests/hello_world_test.rb b/test/requests/hello_world_test.rb new file mode 100644 index 0000000..5c7c548 --- /dev/null +++ b/test/requests/hello_world_test.rb @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb index e0fb32b..cc22127 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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"