Bundle exec rspec spec / static_pages_spec.rb无法加载错误

时间:2012-06-07 20:55:58

标签: ruby-on-rails ruby-on-rails-3 rspec tdd bdd

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

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自动运行“

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失败的测试工作?

1 个答案:

答案 0 :(得分:0)

不要在函数及其开放的parens之间留空格,即

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

应该是

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