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.

Revisions

  1. alvin2ye revised this gist Jan 28, 2019. No changes.
  2. alvin2ye revised this gist Jan 28, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions generate_test_file.rb
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    # curl -sSL https://gist.github.com/alvin2ye/adf04cb32d2dba79d1424a3d70b2bbee/raw/generate_test_file.rb | ruby - "app/controllers/wechat_platform/official_accounts/webhooks_controller.rb"
    # generate spec/controllers/wechat_platform/official_accounts/webhooks_controller_spec.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"

  3. alvin2ye revised this gist Jan 28, 2019. No changes.
  4. alvin2ye revised this gist Jan 28, 2019. 1 changed file with 7 additions and 18 deletions.
    25 changes: 7 additions & 18 deletions generate_test_file.rb
    Original file line number Diff line number Diff line change
    @@ -4,31 +4,20 @@
    require "FileUtils"

    rbfile = ARGV.first
    test_file = rbfile.gsub(/^app/, "spec/").gsub(/_controller\.rb$/, "_controller_spec.rb")
    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 TradeSchemesController, :type => :controller do
    render_views
    describe "put finish_apply" do
    before do
    @trade = create_day_win_trade_scheme({})
    end
    it "success" do
    expect(@trade.reload.status).to eq "are_confirm"
    put :finish_apply, id: @trade.id
    expect(JSON(response.body)['success']).to be true
    expect(@trade.reload.status).to eq "clearing_currency"
    end
    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}"
  5. alvin2ye revised this gist Jan 27, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion generate_test_file.rb
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # echo http://a.rb | ruby - "app/controllers/wechat_platform/official_accounts/webhooks_controller.rb"
    # curl -sSL https://gist.github.com/alvin2ye/adf04cb32d2dba79d1424a3d70b2bbee/raw/generate_test_file.rb | ruby - "app/controllers/wechat_platform/official_accounts/webhooks_controller.rb"
    # generate spec/controllers/wechat_platform/official_accounts/webhooks_controller_spec.rb

    require "FileUtils"
  6. alvin2ye revised this gist Jan 27, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion generate_test_file.rb
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    require "FileUtils"

    rbfile = ARGV.first
    test_file = rbfile.gsub(/^app/spec/).gsub(/_controller\.rb$/, "_controller_spec.rb")
    test_file = rbfile.gsub(/^app/, "spec/").gsub(/_controller\.rb$/, "_controller_spec.rb")

    FileUtils.mkdir_p(File.dirname(test_file))

  7. alvin2ye revised this gist Jan 27, 2019. 1 changed file with 27 additions and 1 deletion.
    28 changes: 27 additions & 1 deletion generate_test_file.rb
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,32 @@
    test_file = rbfile.gsub(/^app/spec/).gsub(/_controller\.rb$/, "_controller_spec.rb")

    FileUtils.mkdir_p(File.dirname(test_file))

    body = <<-EOF
    require 'rails_helper'
    RSpec.describe TradeSchemesController, :type => :controller do
    render_views
    describe "put finish_apply" do
    before do
    @trade = create_day_win_trade_scheme({})
    end
    it "success" do
    expect(@trade.reload.status).to eq "are_confirm"
    put :finish_apply, id: @trade.id
    expect(JSON(response.body)['success']).to be true
    expect(@trade.reload.status).to eq "clearing_currency"
    end
    end
    end
    EOF

    puts "Generate #{test_file}"

    File.open(test_file, "w") do |f|
    f.puts ""
    f.puts body
    end
  8. alvin2ye renamed this gist Jan 27, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  9. alvin2ye revised this gist Jan 27, 2019. 1 changed file with 12 additions and 1 deletion.
    13 changes: 12 additions & 1 deletion test.rb
    Original file line number Diff line number Diff line change
    @@ -1 +1,12 @@
    p ["abc", $*, $1, ARGV]
    # echo http://a.rb | ruby - "app/controllers/wechat_platform/official_accounts/webhooks_controller.rb"
    # generate spec/controllers/wechat_platform/official_accounts/webhooks_controller_spec.rb

    require "FileUtils"

    rbfile = ARGV.first
    test_file = rbfile.gsub(/^app/spec/).gsub(/_controller\.rb$/, "_controller_spec.rb")

    FileUtils.mkdir_p(File.dirname(test_file))
    File.open(test_file, "w") do |f|
    f.puts ""
    end
  10. alvin2ye renamed this gist Jan 27, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  11. alvin2ye created this gist Jan 27, 2019.
    1 change: 1 addition & 0 deletions test
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    p ["abc", $*, $1, ARGV]