简体   繁体   English

Michael Hartl Rails教程第3章RSpec语法错误

[英]Michael Hartl Rails Tutorial Chapter 3 RSpec Syntax Errors

I am attempting to work my way through Hartl's Rails tutorial. 我正在尝试通过Hartl的Rails教程进行工作。 In working through Chapter 3.2.1, I have now run into the following two errors when attempting 在阅读第3.2.1章时,我现在在尝试时遇到以下两个错误

bundle exec rspec spec/requests/static_pages_spec.rb

Both are syntax errors: 两者都是语法错误:

I:/Programs/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-3.0.3/lib/rspec/core/configuration.rb:1057:in `load': C:/Users/Anastasia/RubymineProjects/sample_app/spec/requests/static_pages_spec.rb:3: syntax error, unexpected keyword_do_block (SyntaxError) I:/程序/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-3.0.3/lib/rspec/core/configuration.rb:1057:在`load'中:C: /Users/Anastasia/RubymineProjects/sample_app/spec/requests/static_pages_spec.rb:3:语法错误,意外的keyword_do_block(SyntaxError)

C:/Users/Anastasia/RubymineProjects/sample_app/spec/requests/static_pages_spec.rb:12: syntax error, unexpected keyword_end, expecting $end C:/Users/Anastasia/RubymineProjects/sample_app/spec/requests/static_pages_spec.rb:12:语法错误,意外的keyword_end,期望$ end

I've gone into each of the two files, and I am not seeing an actual syntax error: 我进入了两个文件中的每一个,但没有看到实际的语法错误:

static_pages_spec.rb contains the following code: static_pages_spec.rb包含以下代码:

require 'spec_helper'

RSpec.describe "StaticPages", do

  describe "Home page" do

    it "should have the content 'Sample App'" do
      visit '/static_pages/home'
      expect(page).to have_content('Sample App')
    end
  end
end

All "do's" seem to have a matching "end." 所有的“做”似乎都有一个匹配的“结尾”。

spec_helper.rb contains the following code: spec_helper.rb包含以下代码:

RSpec.configure do |config|

  config.include Capybara: :DSL

end

Again, the "do" and "end" seem to match. 同样,“ do”和“ end”似乎匹配。

Note: I am very new to coding. 注意:我对编码非常陌生。 My previous experience is html/css-related. 我以前的经验与html / css相关。 I'm currently going through a free trial of Ruby Mine while going through this tutorial, and I can't help but wonder if perhaps it would be better to simply start over with just a text editor like SublimeText, since using RM means I'm not only working to learn Ruby and Rails, but also RM. 我目前正在通过本教程进行Ruby Mine的免费试用,我不禁想知道,仅使用SublimeText这样的文本编辑器是否会更好,因为使用RM意味着我我不仅要学习Ruby和Rails,而且要学习RM。 There are things I really like about RM (I'm a visual person by nature, so having something that's more visually appealing is good, but also I like the gem installation interface, which makes it easy not only to install gems, but also to read their documentation). 关于RM,我真的很喜欢(我本质上是一个视觉化的人,所以拥有一些在视觉上更具吸引力的东西是好事,但我也喜欢gem安装界面,它不仅使安装gem变得容易,而且使阅读他们的文档)。 Another downside to using RM is the version differences between the tutorial and what RM comes bundled with (Ruby 1.9.3 versus 2.0.0, etc) which has led to me electing to leave off the version listings in gemfiles to avoid creating bizarre conflicts (I may be wrong in thinking that will be an issue, but it made logical sense in my mind). 使用RM的另一个缺点是教程与RM捆绑的版本之间存在版本差异(Ruby 1.9.3与2.0.0等),这导致我选择放弃gemfile中的版本列表,以避免产生奇怪的冲突(我认为这将是一个问题,这可能是错误的,但在我看来,这是合乎逻辑的。

The Capybara gem is installed and is in the gemfile, so I don't think that's the issue (could be wrong, though). 该水豚的宝石将被安装并在Gemfile中,所以我不认为这是个问题(可能是错误的,虽然)。 I'm sure I'm just missing something really simple, but I can't for the life of me see what it is. 我确定我只是缺少一些非常简单的东西,但是我一生都看不到它是什么。

Any advice or assistance would be appreciated! 任何建议或协助,将不胜感激!

You have a typo in your code 您的代码中有错字

 RSpec.describe "StaticPages", do

This line shouldn't have that comma 这行不应该有逗号

RSpec.describe "StaticPages" do

if the ends match it is almost surely a comma. 如果两端匹配,则几乎肯定是逗号。 "programming is like writing a book except if you have one extra comma on page 126 the whole thing makes no sense." “编程就像写书,除非您在第126页上有一个逗号,否则整个过程都没有意义。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM