Forum: RSpec webrat methods are undefined

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Tom H. (Guest)
on 2009-01-28 17:15
I am sure it is just a configuration issue, but when I use any of the
steps in the webrat_steps.rb file, I get messages like:

 undefined method `click_link'

I have the webrat gem installed (0.3.4). I have the aslakhellesoy-webrat
(0.3.2.2) gem installed, and I have the webrat plugin installed.

In my cucumber env.rb file I have the following.
  require 'webrat' if !defined?(Webrat)

  # Comment out the next two lines if you're not using RSpec's matchers
(should   should_not) in your steps.
  require 'cucumber/rails/rspec'
  #require 'webrat/rspec-rails'

So I am sure I have munged the setup. Any advice would be appreciated.

Not withstanding, cucumber works, just not the webrat steps

Best,
Tom
Matt W. (Guest)
on 2009-01-28 17:59
(Received via mailing list)
On 28 Jan 2009, at 15:15, Tom H. wrote:

>  require 'webrat' if !defined?(Webrat)
>
>  # Comment out the next two lines if you're not using RSpec's matchers
> (should   should_not) in your steps.
>  require 'cucumber/rails/rspec'
>  #require 'webrat/rspec-rails'
>
> So I am sure I have munged the setup. Any advice would be appreciated.

Hi Tom,

I should update to the new version of webrat (0.4) and cucumber (can't
remember) as this stuff has gone through some churn but stabilised
following that 0.4 release.

Check the webrat docs, but (with that new version) I think you need to
do something like

Webrat.configure do |config|
   config.mode = :rails
end

You won't need the aslakhellesoy gem anymore either I don't think.

Please let us know if you were misguided by any out-of-date
documentation.


Matt W.
http://blog.mattwynne.net
http://www.songkick.com
David C. (Guest)
on 2009-01-28 18:23
(Received via mailing list)
On Wed, Jan 28, 2009 at 9:15 AM, Tom H. <removed_email_address@domain.invalid> 
wrote:
> I am sure it is just a configuration issue, but when I use any of the
> steps in the webrat_steps.rb file, I get messages like:
>
>  undefined method `click_link'
>
> I have the webrat gem installed (0.3.4). I have the aslakhellesoy-webrat
> (0.3.2.2) gem installed, and I have the webrat plugin installed.

I had this problem and upgraded to webrat-0.4.0 and it went away. I
think that the aslakhellesoy-webrat gem was a temporary solution to
incompatibilities and is out of date at this point.

HTH,
David
Tom H. (Guest)
on 2009-01-28 18:29
Hey Matt -

> I should update to the new version of webrat (0.4) and cucumber (can't
> remember) as this stuff has gone through some churn but stabilised
> following that 0.4 release.
>
> Check the webrat docs, but (with that new version) I think you need to
> do something like
>
> Webrat.configure do |config|
>    config.mode = :rails
> end
>
> You won't need the aslakhellesoy gem anymore either I don't think.
>
> Please let us know if you were misguided by any out-of-date
> documentation.
>

I uninstalled the aslakhellesoy gem and installed/updated the webrat gem
to 0.4

I changed the env.rb file to match the docs

Now I get

 `load_missing_constant': Expected
/mnt/hgfs/projects/classroomparent/vendor/plugins/webrat/lib/webrat.rb
to define Webrat (LoadError)

Do I need to have the gem and the plugin both installed?

The documentation I read was here
http://wiki.github.com/aslakhellesoy/cucumber/ruby-on-rails, but it
looks like it has been updated, though it doesn't include the
instructions on configuring webrat.

I really appreciate your help.

Tom
Tom H. (Guest)
on 2009-01-28 18:32
Appears that I did not fully remove the webrat plugin, and this was
causing the problem.

Thanks again for your help.
Tom H. (Guest)
on 2009-01-28 18:55
Tom H. wrote:
> Appears that I did not fully remove the webrat plugin, and this was
> causing the problem.
>
> Thanks again for your help.

Perhaps I should request this in a new topic, but it could be another
simple mistake I am making.

I have the following scenario

Scenario: Login
  Given I am using the "rpems" domain
  Given I am logged in as an admin user
  Then I should see "Classrooms"
  And I should see "School Year: 2008-2009"
  And I should see "Users"


What ends up happening is after the admin login, instead of seeing the
Classrooms page, the next bit of html delivered is

"<html><body>You are being <a
href=\"http://rpems.test/classrooms\">redirected</a>.</bo...

Is there something special I should be doing to handle redirects. After
reading this
(http://www.nabble.com/Cucumber,-Webrat-and-http-ba...)
my impression was that redirects are handled internally to webrat and
cucumber and don't need to be explicitly handled in the scenarios.

Your thoughts are greatly appreciated.

Best,
Tom
Zach D. (Guest)
on 2009-01-28 19:47
(Received via mailing list)
On Wed, Jan 28, 2009 at 11:55 AM, Tom H. <removed_email_address@domain.invalid> 
wrote:
>
>
> "<html><body>You are being <a
> href=\"http://rpems.test/classrooms\">redirected</a>.</bo...
>
> Is there something special I should be doing to handle redirects. After
> reading this
> (http://www.nabble.com/Cucumber,-Webrat-and-http-ba...)
> my impression was that redirects are handled internally to webrat and
> cucumber and don't need to be explicitly handled in the scenarios.
>
> Your thoughts are greatly appreciated.

There are a number of fixes for redirects and subdomain related
functionality which are currently tagged for the 0.4.1 release. I had
this problem after upgrading to 0.4.0, and have since updated to edge
until 0.4.1 is out.

http://webrat.lighthouseapp.com/projects/10503-web...


--
Zach D.
http://www.continuousthinking.com
http://www.mutuallyhuman.com
Tom H. (Guest)
on 2009-01-28 20:37
>
> There are a number of fixes for redirects and subdomain related
> functionality which are currently tagged for the 0.4.1 release. I had
> this problem after upgrading to 0.4.0, and have since updated to edge
> until 0.4.1 is out.
>

Thanks Zach

I installed the edge code (at least I believe I have) by doing a "git
clone" into the vendor/plugins/webrat folder and changing the env.rb
file to no longer require the gem.

However, I am still getting the error. When I attempt to login to my
app, the page that is returned after successful login is

<html><body>You are being <a
href=\"http://rpems.test/classrooms\">redirected</a>.</bo...

instead of the contents of the redirected page.

What generates this message? Is it mongrel? Rails?

I just have to believe that I have something set up incorrectly.
Wouldn't everyone that is using 4.0 and has redirects in their code be
facing the same problem?

Any other ideas?

Thanks
Tom
Josh K. (Guest)
on 2009-01-28 20:49
(Received via mailing list)
On Wed, Jan 28, 2009 at 1:37 PM, Tom H. <removed_email_address@domain.invalid> 
wrote:
> I installed the edge code (at least I believe I have) by doing a "git
> clone" into the vendor/plugins/webrat folder and changing the env.rb
> file to no longer require the gem.
>
> However, I am still getting the error. When I attempt to login to my
> app, the page that is returned after successful login is
>
> <html><body>You are being <a
> href=\"http://rpems.test/classrooms\">redirected</a>.</bo...
>

Hey Tom,

As Zack pointed out I heavily refactored the redirect logic in 0.4,
but missed a few cases which will be included in 0.4.1.  What repo did
you clone from when you installed the plugin?  Assuming it was brynary
or myself then everything should be fine.  If however you are still
seeing problems please give me a little more context as to what URLs
are being request, where they are being redirected to, etc. so that I
can try and track it down.

Thanks.

Josh


--
Josh K.
phone: 509-979-1593
email:  removed_email_address@domain.invalid
web:    http://joshknowles.com
Tom H. (Guest)
on 2009-01-28 21:29
Josh -

I used "git clone git://github.com/brynary/webrat.git". Should I have
used a different repo?

First, I set up the host with my subdomain

  host! "rpems.test"

Then the steps for the admin login:

  visit "/login"
  fill_in("login", :with => "admin")
  fill_in("password", :with => "test")
  click_button("Log in")

Then i check what is returned, looking for the word "Classroom" to
indicate that the user is on the Classrooms page.

So the steps should go
http://rpems.test/
http://rpems.test/login

Then the Log In submit, which, if the login is successful (which it
appears to be), redirects to
http://rpems.test/classrooms

What else could I give you to help track down the issue (if I have
indeed installed the correct repo).

Thanks
Tom
Zach D. (Guest)
on 2009-01-28 21:56
(Received via mailing list)
On Wed, Jan 28, 2009 at 2:29 PM, Tom H. <removed_email_address@domain.invalid> 
wrote:
>
>  visit "/login"
>  fill_in("login", :with => "admin")
>  fill_in("password", :with => "test")
>  click_button("Log in")
>

Try kicking things off with:
   visit login_url(:host =>" rpems.test")

host! is a Rails method, and outside-of the knowledge of Webrat.
Webrat only knows about the URLs and paths that you actually have it
go through. I think this may produce the results you want because
Webrat will be aware from the get-go that you're on as subdomain.

This will probably still break in webrat HEAD, I am using this branch
right now which includes a fix that is not in HEAD (it's waiting to be
merged, or for another solution to take effect):
   http://github.com/zdennis/webrat/tree/make_current...

This ensures that webrat respects subdomains while navigating through
the app. You may want to check it out until one (or al) of the
following tickets are closed:

http://webrat.lighthouseapp.com/projects/10503/tic...
http://webrat.lighthouseapp.com/projects/10503/tic...
http://webrat.lighthouseapp.com/projects/10503/tic...

With the aforementioned branch we haven't hit any new issues using
subdomains in our app's feature suite.


>
> http://rubyforge.org/mailman/listinfo/rspec-users
>



--
Zach D.
http://www.continuousthinking.com
http://www.mutuallyhuman.com
Tom H. (Guest)
on 2009-01-28 23:49
Zach D. wrote:

>
> This will probably still break in webrat HEAD, I am using this branch
> right now which includes a fix that is not in HEAD (it's waiting to be
> merged, or for another solution to take effect):
>    http://github.com/zdennis/webrat/tree/make_current...


I apologize for my newbieness to git, but i have tried several different
ways of trying to checkout the code in your repo and, alas, I have
failed.

if I want to git clone it, what statement should I use?

Thanks again for your help!
Scott T. (Guest)
on 2009-01-28 23:59
(Received via mailing list)
On Jan 28, 2009, at 4:49 PM, Tom H. wrote:

> I apologize for my newbieness to git, but i have tried several
> different
> ways of trying to checkout the code in your repo and, alas, I have
> failed.
>
> if I want to git clone it, what statement should I use?

git clone git://github.com/zdennis/webrat.git
David C. (Guest)
on 2009-01-29 00:00
(Received via mailing list)
On Wed, Jan 28, 2009 at 3:57 PM, Scott T. <removed_email_address@domain.invalid>
wrote:
>>
>>
>> I apologize for my newbieness to git, but i have tried several different
>> ways of trying to checkout the code in your repo and, alas, I have
>> failed.
>>
>> if I want to git clone it, what statement should I use?
>
> git clone git://github.com/zdennis/webrat.git

You can get this if you click on the Public Clone URL:
git://github.com/zdennis/webrat.git on
http://github.com/zdennis/webrat/tree/make_current...
Tom H. (Guest)
on 2009-01-29 01:50
Scott T. wrote:

>
> git clone git://github.com/zdennis/webrat.git


I am sorry to be a pain, but i get the following error.

Initialize webrat/.git
Initialized empty Git repository in
c:/projects/pospaw/vendor/plugins/webrat/.git/
fatal: read error (Invalid argument)

Tom
Tom H. (Guest)
on 2009-02-03 13:58
I was able to download the zip file and lo...the tests ran.

Thanks for all your help!

Tom
Amit K. (Guest)
on 2010-03-10 16:06
Hello,
I recently updated rspec-rails from  1.1.12 to 1.3.0 and rspec from
1.1.12 to 1.3.0
Now while running cucumber i am facing a problem.
It says as 'undefined method 'visit''
my cucumber version is 0.3.99 and webrat version is 0.7.0.
Before upgrading the gem it ran well but now above error is displayed.
My env.rb file is as follows:

ENV["RAILS_ENV"] ||= "test"
require File.expand_path(File.dirname(__FILE__) +
'/../../config/environment')
require 'cucumber/rails/world'

# Comment out the next line if you don't want Cucumber Unicode support
require 'cucumber/formatter/unicode'

# Comment out the next line if you don't want transactions to
# open/roll back around each scenario
Cucumber::Rails.use_transactional_fixtures

Before do
  Fixtures.reset_cache
  fixtures_folder = File.join(RAILS_ROOT, 'spec', 'fixtures')
  fixtures = Dir[File.join(fixtures_folder, '*.yml')].map {|f|
File.basename(f, '.yml') }
  Fixtures.create_fixtures(fixtures_folder, fixtures)
end

# Comment out the next line if you want Rails' own error handling
# (e.g. rescue_action_in_public / rescue_responses / rescue_from)
Cucumber::Rails.bypass_rescue
require 'webrat'
require 'cucumber/webrat/element_locator' # Lets you do
table.diff!(element_at('#my_table_or_dl_or_ul_or_ol').to_table)

Webrat.configure do |config|
  config.mode = :rails
end
require 'cucumber/rails/rspec'
require 'webrat/core/matchers'

Also my config/environments/cucumber.rb contains

config.cache_classes = true # This must be true for Cucumber to operate
correctly!

# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true

# Show full error reports and disable caching
config.action_controller.consider_all_requests_local = true
config.action_controller.perform_caching             = false

# Disable request forgery protection in test environment
config.action_controller.allow_forgery_protection    = false

# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test

config.gem 'cucumber',    :lib => false,        :version => '>=0.3.99'
unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber'))
config.gem 'webrat',      :lib => false,        :version => '>=0.7.0'
unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat'))
config.gem 'rspec',       :lib => false,        :version => '>=1.3.0'
unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec'))
config.gem 'rspec-rails', :lib => 'spec/rails', :version => '>=1.3.2'
unless File.directory?(File.join(Rails.root,
'vendor/plugins/rspec-rails'))

Please suggest
This topic is locked and can not be replied to.