Rails - 让 RSpec 正常工作

发布于 2024-10-22 01:37:05 字数 1342 浏览 2 评论 0原文

我正在学习如何在我的 Rails 应用程序上进行集成测试。我从黄瓜开始,但后来了解到,因为我只是测试模型方法,所以我应该使用 RSPEC。所以现在我正在尝试安装 RSPEC。

当我运行自动测试时,它只查看 /features 目录而不是 /spec 目录。

这是我到目前为止所做的:

.autotest

require 'autotest/growl'
require 'autotest/fsevent'

Autotest.add_hook(:initialize) {|at|
  at.add_exception %r{^\.git}  # ignore Version Control System
  at.add_exception %r{^./tmp}  # ignore temp files, lest autotest will run again, and again...
  #  at.clear_mappings         # take out the default (test/test*rb)
  at.add_mapping(%r{^lib/.*\.rb$}) {|f, _|
    Dir['spec/**/*.rb']
  }
  nil
}


/spec - created directory
/spec/spec_helper.rb - created
/spec/lib/mailingjob_spec.rb - created, tried to write a case that would fail as follows:

require 'spec_helper'

describe User do
  before(:each) do
    @valid_attributes = {
      :login => "akm",
      :email => "[email protected]",
      :password => "D1ff1cultPa55w0rd",
      :password_confirmation => "D1ff1cultPa55w0rd"
    }
  end

  it "should create a new instance given valid attributes" do
    User.create!(@valid_attributesXXXX)
  end
end

但是当我运行自动测试时,这个 rpsec 永远不会运行,只有带有 cucumber 的 features 目录正在运行。有想法吗?谢谢

I'm learning how to do integration testin on my rails app. I started with cucumber but then learned since I'm just testing a models method that I should be using RSPEC. So now I'm trying to get RSPEC installed.

When I run autotest, it is only looking at the /features directory not the /spec directory.

Here's what I've done so far:

.autotest

require 'autotest/growl'
require 'autotest/fsevent'

Autotest.add_hook(:initialize) {|at|
  at.add_exception %r{^\.git}  # ignore Version Control System
  at.add_exception %r{^./tmp}  # ignore temp files, lest autotest will run again, and again...
  #  at.clear_mappings         # take out the default (test/test*rb)
  at.add_mapping(%r{^lib/.*\.rb$}) {|f, _|
    Dir['spec/**/*.rb']
  }
  nil
}


/spec - created directory
/spec/spec_helper.rb - created
/spec/lib/mailingjob_spec.rb - created, tried to write a case that would fail as follows:

require 'spec_helper'

describe User do
  before(:each) do
    @valid_attributes = {
      :login => "akm",
      :email => "[email protected]",
      :password => "D1ff1cultPa55w0rd",
      :password_confirmation => "D1ff1cultPa55w0rd"
    }
  end

  it "should create a new instance given valid attributes" do
    User.create!(@valid_attributesXXXX)
  end
end

But when I run autotest this rpsec is never run only the features dir with cucumber is running. Ideas? thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

來不及說愛妳 2024-10-29 01:37:05

尝试:

rspec --configure autotest

来自自动测试自述文件:

[RSpec] 如果你想使用 require
'spec_helper' -> 'spec_helper' -> rspec --配置
自动测试

Try:

rspec --configure autotest

From the autotest README:

[RSpec] if you want to use require
'spec_helper' -> rspec --configure
autotest

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文