0

I've added this to my spec_helper:

require 'capybara'
require 'capybara/dsl'
require 'capybara/rspec'
require 'selenium-webdriver'
require 'site_prism'

And my page is this:

class AboutPage < SitePrism::Page
end

My rspec is this:

require_relative 'spec_helper'

describe 'About Page' do

  it "test" do
    about = AboutPage.new
  end

end

The error I keep getting is:

Failures:

1) About Page test Failure/Error: about = AboutPage.new NameError: uninitialized constant AboutPage # ./about_spec.rb:6:in `block (2 levels) in '

True_Blue
  • 1,387
  • 2
  • 10
  • 13

3 Answers3

0

If AboutPage is not in the root path of controller, you must call it with a namespace like:

about = SomeNameSpace::AboutPage.new
dddd1919
  • 868
  • 5
  • 13
  • what would be the value of 'SomeNameSpace'?, ie, where could I find that namespace on my project, not quite sure what it refers to... – mickael Nov 19 '16 at 03:53
0

It looks like I needed to add to my spec_helper.rb:

require_relative about_page.rb

All pages you are using in your spec files have to be required before the can be used.

True_Blue
  • 1,387
  • 2
  • 10
  • 13
  • where is that 'spec_helper.rb'? I search for it on my project and saw a few references under Capybara, but I don't think I should be changing a gem just to add my pages, should I? Even like that, I'm just starting on a new project and I cannot see them adding the SitePrism pages added anywhere, but they are able to create objects.Although I'm having the problem where I create a new page and I get this error (I'm asking that question here as I'm not sure why one works and the other doesn't). If you guys can think what I could try, please let me know... – mickael Nov 19 '16 at 03:56
0

If all of your site prism objects are in spec/page_objects, using rspec, you could add this line to rails_helper.rb

Dir[Rails.root.join('spec/page_objects/**/*.rb')].each { |f| require f }

This will automatically require about_page.rb and any other page objects, including subfolders.

Adam Cooper
  • 936
  • 11
  • 16