小编Pau*_*nti的帖子

第9章,Hartl ROR第9.2.2节

我继续得到同样的失败信息,但我似乎无法弄清楚出了什么问题.

失败:

1)访问编辑页面的Users控制器中未登录用户的身份验证授权失败/错误:它{should have_selector('title',text:'登录')}预期的css"title",带有文本"登录"返回#./spec/requests/authentication_pages_spec.rb:69:在'块(6级)中'

2)用户控制器中未登录用户的身份验证授权提交更新操作失败/错误:指定{response.should redirect_to(signin_path)}预期响应为<:redirect>,但<200># ./spec/requests/authentication_pages_spec.rb:74:在'块(6级)中'

完成2.31秒69例,2次失败

失败的例子:

rspec ./spec/requests/authentication_pages_spec.rb:69#访问编辑页面的Users控制器中非登录用户的身份验证授权rspec ./spec/requests/authentication_pages_spec.rb:74#非签名的身份验证授权 - 用户控制器中的用户提交更新操作

这是authentication_pages_spec.rb:require'pec_helper'

描述"身份验证"

subject { page }

describe "signin page" do
    before { visit signin_path }

    it { should have_selector('h1', text: 'Sign in') }
    it { should have_selector('title', text: 'Sign in') }
end

describe "signin" do
    before { visit signin_path }

    describe "with invalid information" do
        before { click_button "Sign in" }

        it { should have_selector('title', text: 'Sign in') }
        it { should have_selector('div.alert.alert-error', text: 'Invalid') } …
Run Code Online (Sandbox Code Playgroud)

rspec ruby-on-rails before-filter ruby-on-rails-3 railstutorial.org

3
推荐指数
1
解决办法
975
查看次数

Rspec测试应该通过但是失败

我从迈克尔哈特尔书中得到了这个测试:

require 'spec_helper'
  describe "Static pages" do
    let(:base_title) { "Ruby on Rails Tutorial Sample App" }

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

      it "should have the title 'Home'" do
        visit '/static_pages/home'
        page.should have_selector('title', :text => "#{base_title} | Home")
      end
  end
end
Run Code Online (Sandbox Code Playgroud)

并且观点:

<% provide(:title, 'Home') %>
<h1>Sample App</h1>
<p>
  This is the home page for the
  <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
  sample application. …
Run Code Online (Sandbox Code Playgroud)

rspec ruby-on-rails erb capybara railstutorial.org

3
推荐指数
1
解决办法
1560
查看次数

Rails教程 - 命名路由

我目前正在研究Michael Hartl的Rails教程并遇到了一个我无法理解的错误.

本教程介绍了如何在routes.rb文件中创建自定义URI.该教程通过对此进行编码来解释:

match '/about', to: 'static_pages#about'
Run Code Online (Sandbox Code Playgroud)

应自动创建如下所示的命名路由:

about_path => '/about'
about_url  => 'http://localhost:3000/about'
Run Code Online (Sandbox Code Playgroud)

以下部分将帮助您通过使用这些变量替换某些代码来修复rspec测试.但是当我这样做时,我最终失败了每一个测试,因为无法找到所有"自动创建的变量"...

任何人都可以向我解释为什么他们没有被找到或者我可以看看他们是否已经实际创建了.

ruby ruby-on-rails railstutorial.org

3
推荐指数
1
解决办法
5525
查看次数

测试从生成的进程中捕获的IO

我想在以下方法上测试返回值和IO输出:

defmodule Speaker do
  def speak do
    receive do
      { :say, msg } ->
        IO.puts(msg)
        speak
      _other ->
        speak # throw away the message
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

ExUnit.CaptureIO文档中,有一个示例测试,它执行此操作,如下所示:

test "checking the return value and the IO output" do
  fun = fn ->
    assert Enum.each(["some", "example"], &(IO.puts &1)) == :ok
  end
  assert capture_io(fun) == "some\nexample\n"
end
Run Code Online (Sandbox Code Playgroud)

鉴于此,我认为我可以编写以下测试,执行类似的操作但使用spawned过程:

test ".speak with capture io" do
  pid = Kernel.spawn(Speaker, :speak, [])
  fun = fn ->
    assert send(pid, { :say, …
Run Code Online (Sandbox Code Playgroud)

io elixir spawn ex-unit

3
推荐指数
1
解决办法
566
查看次数

Rails Footnotes partials count始终为零

我在我的Rails 3.2应用程序中使用rails-footnotes gem,但我似乎无法通过脚注来记录任何部分的存在:它总是显示零部分计数.

为了能够知道在视图中显示多少和哪些部分很容易就像这样,我认为非常有用,所以我真的想让这个工作(其余的工作很棒),但我不确定是什么问题是,我希望其他人有同样的问题,并能够解决它.有没有我可能错过的环境?

我不认为这是相关的,但我使用的是OSX 10.6.8并且在使用宝石与Sublime Text 2正常工作时遇到了一些问题,但它们确实得到了解决(详见StackOverflow的答案).

更新:

似乎问题只存在于haml模板中,因为我得到了erb模板的预期输出.似乎只有erb模板被计算/识别......?

更新2:

@DonHopkins的回答让我所有的Haml模板都注册了Rails脚注.我把它放在我的配置文件中,如下所示:

配置/初始化/ rails_footnotes.rb

if defined?(Footnotes) && Rails.env.development?
  Footnotes.run! # first of all
  Footnotes::Notes::LogNote::LoggingExtensions.module_eval do
    def add(*args, &block)
      super
      logged_message = args[2] + "\n"
      Footnotes::Notes::LogNote.log(logged_message)
      logged_message
    end
  end

  # ... other init code
  Footnotes::Filter.prefix = 'subl://open?url=file://%s&line=%d&column=%d'
end 
Run Code Online (Sandbox Code Playgroud)

debugging ruby-on-rails footnotes ruby-on-rails-3 ruby-on-rails-3.2

2
推荐指数
1
解决办法
314
查看次数

当预期输出正确时,Rspec has_selector错误

我有3个rspec选择器失败时,他们都应该成功.我跟随rails-tutorial.org书和他的节目一样正确.

PagesController GET 'home' should have the right title
     Failure/Error: response.should have_selector("title", :content => "Ruby on Rails     Sample App | Home")
       expected following output to contain a <title>Ruby on Rails Sample App | Home</title> tag:
   <!DOCTYPE html>
   <html>
   <head>
   <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
   <title>Ruby on Rails Tutorial Sample App | Home</title>
   </head>
Run Code Online (Sandbox Code Playgroud)

与'内容'和'约'完全相同的错误

application.html.erb

<!DOCTYPE html>
<html>
<head>
    <title><%= title %></title>
    <%= csrf_meta_tag %>
</head>
<body>
    <%= yield %>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

home.html.erb

    <h1>Sample App</h1>
    <p>
    This is the home page …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails capybara rspec-rails railstutorial.org

1
推荐指数
1
解决办法
3884
查看次数

文本框中仅允许使用半角片假名(日语)字符

在我的Rails应用中,我有一个像这样的文本字段

<%= f.text_field :guaranter_furigana_name, autocomplete: "off", class: "form-control", placeholder: "????? ?????????", maxlength: "50",  :disabled => @disabled_field %>
Run Code Online (Sandbox Code Playgroud)

我正在使用jQuery验证此文本字段仅接受半角片假名字符(从ff60到ff9f的Unicode值)。这就是我尝试过的

// Allow only half width kana for guranter ????
$(function (){
  $("#t_user_name_register_guaranter_furigana_name").on("input", function(e){

    var key = e.keyCode || e.charCode;

    var inp = String.fromCharCode(key);

    var kanaregexp = new RegExp('[\uff00-\uff9f]');
    if (kanaregexp.test(inp) != true){
      if( key != 8 && key != 46 && key != 32){
        inp = $(this).val();
        $(this).val(inp.slice(0,-1));
        $("#telno_errmsg").html("?????????????????").show().fadeOut(3000);
        return false;
      }
    }
  });
});
Run Code Online (Sandbox Code Playgroud)

该代码是一团糟,并不总是能正常工作。请帮忙

validation jquery ruby-on-rails cjk

1
推荐指数
1
解决办法
2813
查看次数