尝试运行包含页面对象的测试时出现语法错误

时间:2013-08-09 15:13:20

标签: page-object-gem

我最近选择了页面对象gem,但是当我包含这个gem时,我无法让我的测试(基于Cucumber / Selenium)运行。

根据宝石列表,我安装了宝石:

page-object (0.9.1)

我的env.rb文件包含:

require 'page-object'

但是,当我尝试运行测试时,收到以下错误:

  

/Library/Ruby/Gems/1.8/gems/page-object-0.9.1/lib/page-object/widgets.rb:32:语法错误,意外'=',期待'|'   ... dget_tag do | name,identifier = {:index => 0},& block |                                 ^   /Library/Ruby/Gems/1.8/gems/page-object-0.9.1/lib/page-object/widgets.rb:32:语法错误,意外',',期待kEND   ... ame,identifier = {:index => 0},& block |                                 ^   /Library/Ruby/Gems/1.8/gems/page-object-0.9.1/lib/page-object/widgets.rb:122:语法错误,意外的kEND,期待$ end(SyntaxError)   /Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:51:in gem_original_require' /Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:51:in require'   /Library/Ruby/Gems/1.8/gems/page-object-0.9.1/lib/page-object.rb:10   />Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:116:in gem_original_require' />Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:116:in require'   /Users/garethbragg/dev/trade-finder/test/cucumber/features/support/env.rb:6   /Library/Ruby/Gems/1.8/gems/cucumber-1.3.5/bin/../lib/cucumber/rb_support/rb_language.rb:122:in load' /Library/Ruby/Gems/1.8/gems/cucumber-1.3.5/bin/../lib/cucumber/rb_support/rb_language.rb:122:in load_code_file'   /Library/Ruby/Gems/1.8/gems/cucumber-1.3.5/bin/../lib/cucumber/runtime/support_code.rb:180:in load_file' /Library/Ruby/Gems/1.8/gems/cucumber-1.3.5/bin/../lib/cucumber/runtime/support_code.rb:83:in load_files!'   /Library/Ruby/Gems/1.8/gems/cucumber-1.3.5/bin/../lib/cucumber/runtime/support_code.rb:82:in each' /Library/Ruby/Gems/1.8/gems/cucumber-1.3.5/bin/../lib/cucumber/runtime/support_code.rb:82:in load_files!'   /Library/Ruby/Gems/1.8/gems/cucumber-1.3.5/bin/../lib/cucumber/runtime.rb:183:in load_step_definitions' /Library/Ruby/Gems/1.8/gems/cucumber-1.3.5/bin/../lib/cucumber/runtime.rb:42:in运行!'   /Library/Ruby/Gems/1.8/gems/cucumber-1.3.5/bin/../lib/cucumber/cli/main.rb:47:in execute!' /Library/Ruby/Gems/1.8/gems/cucumber-1.3.5/bin/cucumber:13 /usr/bin/cucumber:23:in load'   的/ usr /斌/黄瓜:23

如果我在任何课程中包含PageObject,我会收到以下内容:

  

未初始化的常量Home :: PageObject(NameError)   ./lib/Home.rb:4   /Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:51:in gem_original_require' /Library/Ruby/Site/1.8/rubygems/core_ext/kernel_require.rb:51:in require'   /Users/garethbragg/dev/trade-finder/test/cucumber/features/support/env.rb:2   /Library/Ruby/Gems/1.8/gems/cucumber-1.3.5/bin/../lib/cucumber/rb_support/rb_language.rb:122:in load' /Library/Ruby/Gems/1.8/gems/cucumber-1.3.5/bin/../lib/cucumber/rb_support/rb_language.rb:122:in load_code_file'   /Library/Ruby/Gems/1.8/gems/cucumber-1.3.5/bin/../lib/cucumber/runtime/support_code.rb:180:in load_file' /Library/Ruby/Gems/1.8/gems/cucumber-1.3.5/bin/../lib/cucumber/runtime/support_code.rb:83:in load_files!'   /Library/Ruby/Gems/1.8/gems/cucumber-1.3.5/bin/../lib/cucumber/runtime/support_code.rb:82:in each' /Library/Ruby/Gems/1.8/gems/cucumber-1.3.5/bin/../lib/cucumber/runtime/support_code.rb:82:in load_files!'   /Library/Ruby/Gems/1.8/gems/cucumber-1.3.5/bin/../lib/cucumber/runtime.rb:183:in load_step_definitions' /Library/Ruby/Gems/1.8/gems/cucumber-1.3.5/bin/../lib/cucumber/runtime.rb:42:in运行!'   /Library/Ruby/Gems/1.8/gems/cucumber-1.3.5/bin/../lib/cucumber/cli/main.rb:47:in execute!' /Library/Ruby/Gems/1.8/gems/cucumber-1.3.5/bin/cucumber:13 /usr/bin/cucumber:23:in load'   的/ usr /斌/黄瓜:23

任何建议都将不胜感激。

2 个答案:

答案 0 :(得分:1)

我认为错误是由于您使用ruby 1.8。你能试试1.9或更高版本吗?

答案 1 :(得分:0)

我今天早些时候遇到了同样的问题。我修改它(如Cheezy建议的那样),更新我的ruby版本。 (1.9.3)。

值得注意的是,我更新了rubygems,删除了我的Gemfile.lock,并运行了另一个bundle install。 (我也使用rvm作为我的ruby版本)