0

我正在尝试使用 Michael Hartl 的教程测试 Rails 应用程序,但输入后出现以下错误bundle exec rspec spec/requests/static_pages_spec.rb(我在示例应用程序目录中)

static_pages_spec.rb:9: 语法错误,意外的 ',',期待 ')' (SyntaxError) ...age.should have_selector ('h1', :text => 'Sample App')

... ^

/Users/subalcharla/subal_rails/sample_app/spec/requests/static_pages_spec.rb:9:语法错误,意外')',期待keyword_end ...r('h1',:text =>'示例应用程序')

/Users/subalcharla/subal_rails/sample_app/spec/requests/static_pages_spec.rb:14: syntax error, 意外',', 期待')' page.should have_selector ('title',

                                                       ^

/Users/subalcharla/subal_rails/sample_app/spec/requests/static_pages_spec.rb:15:语法错误,意外')',期待keyword_end ...ls教程示例应用程序| 家”)

/Users/subalcharla/subal_rails/sample_app/spec/requests/static_pages_spec.rb:49:语法错误,意外')',期待keyword_end

from /Users/subalcharla/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `block in load_spec_files'

from /Users/subalcharla/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `map'

来自 /Users/subalcharla/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `load_spec_files'

来自 /Users/subalcharla/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rspec-core-2.10.1/lib/rspec/core/command_line.rb:22:in `run'

来自 /Users/subalcharla/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:69:in `run'

来自 /Users/subalcharla/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:10:in `block in autorun'

My static_pages_spec.rb file is

需要'spec_helper'

描述“静态页面”做

describe "Home page" do

    it "should have the content 'Sample App'" do  
                    visit '/static_pages/home'
                    page.should have_selector ('h1', :text => 'Sample App') 
    end 

    it "should have the right title" do
                    visit '/static_pages/home'
                    page.should have_selector ('title', 
                  :text => "Ruby on Rails Tutorial Sample App | Home")   
    end

end


describe "Help page" do

    it "should have the content 'Help'" do
      visit '/static_pages/help'
      page.should have_selector('h1', :text => 'Help')
    end

    it "should have the right title" do
      visit '/static_pages/help' 
      page.should have_selector ('title',
        :text => "Ruby on Rails Tutorial Sample App | Help")

    end

end


describe "About page" do

  it "should have the content 'About Us'" do
        visit '/static_pages/about'
        page.should have_selector ('h1', :text => 'About Us')

      end 

  it "should have the right title" do
        visit '/static_pages/about'
        page.should have_selector ('title',
        :text => "Ruby on Rails Tutorial Sample App | About Us")
      end


end

结尾

我已经用教程截屏检查了我的测试文件,它看起来是一样的。什么可能导致 RED 测试失败?

4

1 回答 1

0

不要在函数和它的左括号之间留下空格,即

page.should have_selector ('h1', :text => 'Sample App')

应该

page.should have_selector('h1', :text => 'Sample App') 
于 2012-06-07T21:08:49.047 回答