Skip to content

Instantly share code, notes, and snippets.

@alvin2ye
Last active January 28, 2019 03:17
Show Gist options
  • Save alvin2ye/adf04cb32d2dba79d1424a3d70b2bbee to your computer and use it in GitHub Desktop.
Save alvin2ye/adf04cb32d2dba79d1424a3d70b2bbee to your computer and use it in GitHub Desktop.
generate_test_file.rb
# curl -sSL https://git.io/generate_test_file | ruby - "app/controllers/wechat_platform/official_accounts/webhooks_controller.rb"
# generate spec/requests/wechat_platform/official_accounts/webhooks_controller_spec.rb
require "FileUtils"
rbfile = ARGV.first
test_file = rbfile.gsub(/^app\/controller/, "spec/request").gsub(/_controller\.rb$/, "_controller_spec.rb")
FileUtils.mkdir_p(File.dirname(test_file))
body = <<-EOF
require "rails_helper"
RSpec.describe "WechatPlatform::OfficialAccounts::WebhooksController", type: :request do
it "show" do
get "/wechat_platform/official_accounts/1/webhook", params: {echostr: "aa"}
expect(response.body).to eq "aa"
end
end
EOF
puts "Generate #{test_file}"
File.open(test_file, "w") do |f|
f.puts body
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment