rspec没有找到例子

时间:2014-07-29 01:59:21

标签: ruby rspec

以下是代码:

require_relative "simon_says"

describe "simon says" do
  describe "echo" do
    it "should echo hello" do
      echo("hello").should == "hello"
    end

    it "should echo bye" do
      echo("bye").should == "bye"
    end
  end

  describe "shout" do
    it "should shout hello" do
      shout("hello").should == "HELLO"
    end

    it "should shout multiple words" do
      shout("hello world").should == "HELLO WORLD"
    end
  end

  describe "repeat" do
    it "should repeat" do
      repeat("hello").should == "hello hello"
    end

    # Wait a second! How can you make the "repeat" method
    # take one *or* two arguments?
    #
    # Hint: *default values*
    it "should repeat a number of times" do
      repeat("hello", 3).should == "hello hello hello"
    end
  end

  describe "start_of_word" do
    it "returns the first letter" do
      start_of_word("hello", 1).should == "h"
    end

    it "returns the first two letters" do
      start_of_word("Bob", 2).should == "Bo"
    end

    it "returns the first several letters" do
      s = "abcdefg"
      start_of_word(s, 1).should == "a"
      start_of_word(s, 2).should == "ab"
      start_of_word(s, 3).should == "abc"
    end
  end

  describe "first_word" do
    it "tells us the first word of 'Hello World' is 'Hello'" do
      first_word("Hello World").should == "Hello"
    end

    it "tells us the first word of 'oh dear' is 'oh'" do
      first_word("oh dear").should == "oh"
    end
  end

  describe "titleize" do
    it "capitalizes a word" do
      titleize("jaws").should == "Jaws"
    end

    it "capitalizes every word (aka title case)" do
      titleize("david copperfield").should == "David Copperfield"
    end

    it "doesn't capitalize 'little words' in a title" do
      titleize("war and peace").should == "War and Peace"
    end

    it "does capitalize 'little words' at the start of a title" do
      titleize("the bridge over the river kwai").should == "The Bridge over the River Kwai"
    end
  end

end

但是当我运行它时,它说没有找到例子。 任何人都可以帮助我吗?

2 个答案:

答案 0 :(得分:2)

(很抱歉没有看到这个 - 我希望你能继续使用它)

当你指出错误的文件时,该错误。如果你在rspec中执行lib / simon_says,你会得到“没有找到示例”,请使用spec中的文件进行尝试。

如果你去终端只输入rspec(c之后的空格)然后将03_simon_says_spec.rb拖到终端,你将获得整个路径

例如:rspec /Users/james/mainTestFolder/spec/03_simon_says_spec.rb

它会正确找到lib / 03_simon_says.rb

答案 1 :(得分:0)

如果您将文件拖入终端并且rspec注意到该文件,我建议您使用主系统目录,例如/ Documents文件夹,我注意到终端应用程序有时需要处理整个文件路径,除非它在系统目录中。