2016-05-03 76 views
3

我是Ruby新手,在各種開源軟件中,我注意到一些RSpec描述中的一些「陳述」,看起來並沒有達到他們的意圖,就像他們想要斷言,但沒有。這些編碼錯誤還是存在一些RSpec或Ruby魔法? (奇怪的重載操作符的可能性?)代碼實際上在RSpec中聲明?

這個例子,用#?添加到可疑行:

(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 
+0

很難確定這些行的目的是什麼(從調試中遺留下來?有人想創建一個斷言,但沒有完成它?)。它們並不是真正的錯誤,因爲它們對示例是否會失敗或通過沒有任何影響(只要它們引用的方法在那裏)。但除此之外,這些行只是無用的代碼... –

回答

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)

相關問題