title: Rails, stripe feature test error - param is missing or the value is empty: charge
body: <p>I am trying to write feature tests for my RoR app where users have to pay to submit a post. The user journey is;</p>
  
  <ol>
  <li>User creates a post and selects the button 'proceed to payment'</li>
  <li>User is then taken to a billing page where they can fill in 'card number' 'card verification' and 'card expiry', user then presses 'pay' button. The payment is processed by Stripe. It is not the pop-up widget, but a custom form.</li>
  <li>If successful, the user is redirected to their live post </li>
  </ol>
  
  <p>I have a post model and a charge model. Post has_one charge. Charge belongs_to post. The payments are one-off payments, not subscriptions. </p>
  
  <p>My Post Controller (create action only):</p>
  
  <pre><code>def create
    @post = Post.new(post_params)
    @post.user = current_user
    @amount = 500
    if @post.save
      redirect_to new_post_charge_path(@post.id)
    else
      flash[:error] = "There was an error saving the post. Please try again."
      render :new
    end  
  end
  </code></pre>
  
  <p>My Charge Controller (create action only):</p>
  
  <pre><code>def create
    @charge = Charge.new(charge_params)
    @post = Post.find(params[:post_id]);
    @charge.post = @post
  
      if @charge.save
        Stripe::Charge.create(
          :amount =&gt; 500,
          :currency =&gt; "gbp",
          :source =&gt; params[:charge][:token],
          :description =&gt; "Wikipost #{@post.id}, #{current_user.email}",
          :receipt_email =&gt; current_user.email
        )
        @post.stripe_card_token = @charge.stripe
        @post.live = true
        @post.save
  
        redirect_to @post, notice: 'Post published successfully'
      else
        redirect_to new_post_charge_path(@post.id)
      end
  
      rescue Stripe::CardError =&gt; e
        flash[:error] = e.message
        return redirect_to new_post_charge_path(@post.id)
    end
  </code></pre>
  
  <p>I am testing with rspec/capybara and am trying to write a feature test like below, but I keep getting the error 'param is missing or the value is empty: charge';</p>
  
  <pre><code>require 'rails_helper'
  
  feature 'Publish post' do
  
    before do
      @user = create(:user)
    end
  
    scenario 'successfully as a registered user', :js =&gt; true do
      sign_in_as(@user)
      click_link 'New post'
  
      expect(current_path).to eq('/posts/new')
      fill_in 'post_title', with: 'My new post'
      fill_in 'textarea1', with: 'Ipsum lorem.....'
  
      click_button 'Proceed to Payment'
  
      expect(page).to have_content('Billing')
  
      within 'form#new_charge' do
        fill_card_details
        click_button 'Proceed to Payment'
      end
  
      expect(page).to have_content('My new post - published')
    end
  </code></pre>
  
  <p>What is the best way to fix the error or write a test for this user journey?</p>