代码在RSpec中实际上没有声明?

时间:2016-05-03 22:15:13

标签: ruby rspec

我是Ruby的新手,在各种开源软件中,我注意到了很多"陈述"在某些RSpec描述中似乎没有达到他们想要的目的,就像他们想要做出断言,但没有。这些编码错误还是存在一些RSpec或Ruby魔法? (奇怪的是,运营商超负荷?)

示例,#???添加到可疑线:

(Rubinius的/规格/红宝石/型芯/阵列/ permutation_spec.rb)

it "returns no permutations when the given length has no permutations" do
  @numbers.permutation(9).entries.size == 0        #???
  @numbers.permutation(9) { |n| @yielded << n }
  @yielded.should == []
end

(话语/规格/模型/ topic_link_spec.rb)

it 'works' do
  # ensure other_topic has a post
  post

  url = "http://#{test_uri.host}/t/#{other_topic.slug}/#{other_topic.id}"

  topic.posts.create(user: user, raw: 'initial post')
  linked_post = topic.posts.create(user: user, raw: "Link to another topic: #{url}")

  TopicLink.extract_from(linked_post)

  link = topic.topic_links.first
  expect(link).to be_present
  expect(link).to be_internal
  expect(link.url).to eq(url)
  expect(link.domain).to eq(test_uri.host)

  link.link_topic_id == other_topic.id       #???
  expect(link).not_to be_reflection

  ...

(厨师/规格/单元/ chef_fs / parallelizer.rb)

context "With :ordered => false (unordered output)" do
  it "An empty input produces an empty output" do
    parallelize([], :ordered => false) do
      sleep 10
    end.to_a == []                        #???
    expect(elapsed_time).to be < 0.1
  end

(炉腹/规格/外部/ aws_bootstrap_spec.rb)

it "configures ELBs" do
  load_balancer = elb.load_balancers.detect { |lb| lb.name == "cfrouter" }
  expect(load_balancer).not_to be_nil
  expect(load_balancer.subnets.sort {|s1, s2| s1.id <=> s2.id }).to eq([cf_elb1_subnet, cf_elb2_subnet].sort {|s1, s2| s1.id <=> s2.id })
  expect(load_balancer.security_groups.map(&:name)).to eq(["web"])

  config = Bosh::AwsCliPlugin::AwsConfig.new(aws_configuration_template)
  hosted_zone = route53.hosted_zones.detect { |zone| zone.name == "#{config.vpc_generated_domain}." }
  record_set = hosted_zone.resource_record_sets["\\052.#{config.vpc_generated_domain}.", 'CNAME'] # E.g. "*.midway.cf-app.com."
  expect(record_set).not_to be_nil
  record_set.resource_records.first[:value] == load_balancer.dns_name   #???
  expect(record_set.ttl).to eq(60)
end

2 个答案:

答案 0 :(得分:1)

我认为没有任何特殊行为。我认为您在测试代码中发现了错误。

答案 1 :(得分:0)

这不起作用,因为没有断言,只有比较:

@numbers.permutation(9).entries.size == 0

需要写成:

@numbers.permutation(9).entries.size.should == 0

或使用较新的RSpec语法:

expect(@numbers.permutation(9).entries.size).to eq(0)