我不明白红宝石中的布尔值

时间:2014-09-29 11:53:21

标签: ruby

我的代码,在我的文件规范中

describe TestChamber::Account_v1 do
    let(:agree) { nil }
    let(:agree) { nil }

    let(:account) do
    TestChamber::Account_v1.new(
      :agree => agree,
      :agree1 => agree
    )
  end

    context "when tested account v1" do
    let(:agree) {true}
    let(:agree1) {false}
    it "test account" do
      account.create_account
    end
  end

我的文件库我得到两个参数然后将它们放在终端

   def initialize(options={})
      @agree = options[:@agree]
      @agree1 = options[:@agree1]
    end
    def create_account
          if (@agree == true)
            puts "abc"
          end
      if (@agree1 != false)
        puts "abc1"
      end
   end

我的输出

abc1

任何人都可以向我解释这段代码吗?

1 个答案:

答案 0 :(得分:2)

您正在设置:

@agree = options[:@agree]
@agree1 = options[:@agree1]

替换为:

@agree = options[:agree]
@agree1 = options[:agree1]

应该解决分配问题。

此外,在您的spec文件中:

let(:agree) { nil }
let(:agree) { nil }

第二个应该是agree1。再往下:

TestChamber::Account_v1.new(
  :agree => agree,
  :agree1 => agree
)

同样,这应该是:agree1 => agree1