Question

So it seems like I've used current_path many times in request specs. However, Capybara now requires specs to be in the features directory in order to use the Capybara DSL (page & visit)

# creating_posts_spec.rb

require "spec_helper"

feature "creating posts" do

  scenario "creating posts with valid info is successful" do
    visit new_post_path
    fill_in 'Title', with: "This is a title test"
    fill_in 'Content', with: "This is a content test"
    click_button 'Create Post'
    page.should have_content 'Post was successfully created.'
    page.current_path.should == post_path(post)
  end
end

Its a simple post controller and the page lands on show after the post is rendered just fine in the browser.

 posts GET    /posts(.:format)               posts#index
                     POST   /posts(.:format)               posts#create
            new_post GET    /posts/new(.:format)           posts#new
           edit_post GET    /posts/:id/edit(.:format)      posts#edit
                post GET    /posts/:id(.:format)           posts#show
                     PUT    /posts/:id(.:format)           posts#update
                     DELETE /posts/:id(.:format)           posts#destroy
                root        /                              posts#index

Why am i getting an error: undefined local variable or method 'post'?

I just don't remember ever having this trouble. Anyone have a suggestion or reason? or am I missing something obvious? It's late

Was it helpful?

Solution

Because post is undefined.... You don't set it anywhere in the entire scenario.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top