mickael mickael - 1 month ago 30
Ruby Question

Unable to create new pages: uninitialized constant error with SitePrism page

There are a couple of similar questions but my issue seems different as I am basically copying a file that's currently working.

I joined a team where the last person left a cucumber/ruby framework with the following set up:

  • lib/pages/page1.rb

  • where page1.rb = class PageOne < SitePrism::Page

  • and they just create a new object as: @new_page_one = PageOne.new

I've searched in the whole code to see if he had 'require' or 'include' that 'page1.rb', 'page1', or 'PageOne' anywhere and he didn't, but even like that it works when one tries to create a new object.

So, now I wanted to create a new class and I just copied and pasted the working file in the same location and renamed all as follows:

  • lib/pages/page2.rb

  • where page2.rb = class PageTwo < SitePrism::Page

The problem I'm having is that when I try to create a new object I get this error:
- @new_page_two = PageTwo.new

NameError: uninitialized constant PageTwo

Any idea why the 1st one works and the copy/paste doesn't in this case? Anything you could suggest I try my end please?


Finally, I found it. It seems it was an issue with this particular project.

There was a file which was loading the CLASSES in real time, although they were hard coding part of the file name, hence that my new file was not found, ie,

they were loading *1.rb pages, whereas I made a copy and rename it to page2.rb...