sambehera
sambehera

Reputation: 968

Error with watir trying to match copyright statement

Hi I'm using watir with rspec and am running into problems with the following chunk of code:

I cant understand what Im doing wrong. The exact error I get is "syntax error, unexpected $end, expecting keyword_end @b.text.include? "Ark © 1"

describe "Copyright statement" do 
   it "should exist" do 
    @b.text.include? "Ark © 1"
   end
end

Any help would be appreciated. Thanks.

Upvotes: 2

Views: 393

Answers (3)

sambehera
sambehera

Reputation: 968

I found a solution on the web while searching for the error "invalid multibyte char (US-ASCII)"

Adding this line to the top helps with the copyright statement!

# encoding: UTF-8

Its just a simple comment at the top of the file, but it solves the problem with the copyright character and Rspec/Ruby 1.9.

Thank you everyone for all your help and support. I really do appreciate it!

Upvotes: 1

Chuck van der Linden
Chuck van der Linden

Reputation: 6660

@SteveRobillard has addressed the missing end error message in his reply, but you have another big problem with how you are trying to use rspec there. The problem is that you are not really doing anything with the results of the .include? method since there is no .should there. Your code is executing the method, but just effectively tossing the 'true' or 'false' that is returned into the bit-bucket. That test will never fail because you are missing any kind of validation. I think that line needs to be closer to

describe "Copyright statement" do 
   it "should exist" do 
     @b.text.should include "Ark © 1"
   end 
end     

Correcting that probably will not fix your missing end issue, but without something like that, your 'tests' are not actually testing anything.

Also if it was me, I'd not only want to see that the copyright was somewhere in the html, but in a specific place such as the footer, which is typically inside some kind of container such as a div. If that div had an id of 'footer' then that part of the code would be like this

it "should be found within the footer" do
  @browser.div(:id => 'footer').text.should include 'copyright © Yoyodyne 1984'
end

A good way to see rspec used with Watir is to look at the rspec files for watir itself, for example the spec for a div element and all the tests for what it should do is at https://github.com/watir/watirspec/blob/master/div_spec.rb

Upvotes: 1

Steve Robillard
Steve Robillard

Reputation: 13471

I think your indentation is off the first end needs another space to line up.

describe "Copyright statement" do 
   it "should exist" do 
    @b.text.include? "Ark © 1"
   end 
end

Once you correct this you should be able to see what @ChuckvanderLinden and I think is the real problem - that you are missing and end, but without seeing the rest of the file we can't be sure.

I did come across this tip from Dave Thomas,

http://pragdave.blogs.pragprog.com/pragdave/2008/12/ruby-19-can-check-your-indentation.html

if you run the file with the -w flag it will give you a much better idea of the problem and where exactly it is in your code.

ruby -w samplefile.rb

this will give you output similar to the following:

t.rb:5: warning: mismatched indentations at 'end' with 'if' at 3
t.rb:9: warning: mismatched indentations at 'end' with 'def' at 2
t.rb:10: syntax error, unexpected $end, expecting keyword_end

Making it much easier to locate your error,

Upvotes: 1

Related Questions