Reputation: 149
The method "expect" it not accessible when trying to call from a class method. However, it works fine when calling from the feature spec.So basically the last method (i_expect_to_see_article_on_home_page) is not working.
require 'rails_helper'
class ArticleForm
include Capybara::DSL
def visit_home_page
visit('/')
self
end
def create_an_article
click_on('New Article')
fill_in('Title', with: "My title")
fill_in('Content', with: "My content")
click_on('Create Article')
self
end
def i_expect_to_see_article_on_home_page
visit('/')
expect(page).to have_text("My title")
expect(page).to have_text("My content")
self
end
end
require 'rails_helper'
require_relative '../support/ArticelForm.rb'
feature "home page" do
article_form = ArticleForm.new
scenario "Visit the home page and post an article" do
article_form.visit_home_page.create_an_article
article_form.visit_home_page.i_expect_to_see_article_on_home_page
end
end
Upvotes: 0
Views: 170
Reputation: 49950
You need to include RSpec::Matchers
in your object. You will probably also need to do the same with Capybara::RSpecMatchers if you want to use the capybara matchers
Upvotes: 1
Reputation: 2783
Im not familiar with the syntax you're using but I believe you need to wrap it into "it block".This is how I normally write it:
describe "i_expect_to_see_article_on_home_page" do
it 'should do something' do
visit('/')
expect(page).to have_text("My title")
expect(page).to have_text("My content")
end
end
Upvotes: 0