English 中文(简体)
Rspec: Test Mongo 地图查询
原标题:Rspec: Testing MongoMapper query

我有办法:

def fb_matches_for_friend_employer_goals(user, friend)
    User.where( :is_reachable_on_fb   => true,                          # Users that are reachable on FB via wall posts
                "jobs.employer"       => friend.interested_employers,   # Users that have worked at the employers the friend is interested
                :fb_user_id           => user.fb_connections,           # Users that are friends of user through FB
                :fb_user_id.nin       => friend.fb_connections,         # Users that are NOT friends with the friend through FB
                :fb_user_id.ne        => user.fb_user_id,               # Users that are NOT the user
                :fb_user_id.ne        => friend.fb_user_id              # Users that are NOT the friend (although it s likely the friend hasn t worked at the goal employer)
    ).fields(:id, :jobs, :fb_connections).all
  end 

测试:

  describe "#fb_matches_for_friend_employer_goals method" do
    let(:friend) { stub_model(User) }

    before(:each) do
      User.stub(where: User, fields: User, all: User)
      friend.stub(interested_employers: ["Apple"])
      friend.stub(fb_connections: ["100", "200"])
      friend.stub(fb_user_id: "1")        
      user.stub(fb_connections: ["101", "201"])
      user.stub(fb_user_id: "2")
    end

    it "returns users that are reachable on FB" do
      User.should_receive(:where).with( :is_reachable_on_fb   => true,
                                        "jobs.employer"       => ["Apple"],
                                        :fb_user_id           => ["101", "201"],
                                        :fb_user_id.nin       => ["100", "200"],
                                        :fb_user_id.ne        => "2",
                                        :fb_user_id.ne        => "1")
      a.fb_matches_for_friend_employer_goals(user, friend)
    end

  end

我有以下错误:

Failures:

    1) Algorithm::Helpers::Facebook#fb_matches_for_friend_employer_goals method returns users           that are reachable on FB
 Failure/Error: User.should_receive(:where).with( :is_reachable_on_fb   => true,
   <User (class)> received :where with unexpected arguments
     expected: ({:is_reachable_on_fb=>true, "jobs.employer"=>["Apple"], :fb_user_id=>["101", "201"], #<SymbolOperator:0x007f9e28bac958 @field=:fb_user_id, @operator="nin">=>["100", "200"], #<SymbolOperator:0x007f9e28bac778 @field=:fb_user_id, @operator="ne">=>"2", #<SymbolOperator:0x007f9e28bac688 @field=:fb_user_id, @operator="ne">=>"1"})
          got: ({:is_reachable_on_fb=>true, "jobs.employer"=>["Apple"], :fb_user_id=>["101", "201"], #<SymbolOperator:0x007f9e28babcd8 @field=:fb_user_id, @operator="nin">=>["100", "200"], #<SymbolOperator:0x007f9e28bab6c0 @field=:fb_user_id, @operator="ne">=>"2", #<SymbolOperator:0x007f9e28bab148 @field=:fb_user_id, @operator="ne">=>"1"})
 # ./spec/lib/algorithm/helpers/facebook_spec.rb:44:in `block (3 levels) in <module:Helpers> 

从我可以告诉的角度来看,这只是说,文号的编辑有所不同。 关于如何避免这种情况和确认右面的思想正在问世?

最佳回答

问题与平等的方式有关,在Ruby。

1.9.2-p0 :001 > :something.nin == :something.nin
 => true
1.9.2-p0 :002 > {:something.nin =>  hi } == {:something.nin =>  hi }
 => false
1.9.2-p0 :003 > {:something =>  hi } == {:something =>  hi }
 => true

为了提高效率,I guess Duncan正在比较过去编码,而不是进行实际的<编码>=比较。

1.9.2-p0 :004 > {:something =>  hi }.hash
 => 2493047093815769983 
1.9.2-p0 :005 > {:something =>  hi }.hash
 => 2493047093815769983
1.9.2-p0 :006 > {:something.nin =>  hi }.hash
 => 2609636779135588412
1.9.2-p0 :007 > {:something.nin =>  hi }.hash
 => -424522258459261487
1.9.2-p0 :008 > :something.hash
 => 3062293424662012631
1.9.2-p0 :009 > :something.hash
 => 3062293424662012631
1.9.2-p0 :010 > :something.nin.hash
 => -1304763062464413657 
1.9.2-p0 :011 > :something.nin.hash
 => 2727789822935992035

您的麻烦最永久的固定点是:为象征操作者界定,并向https://github.com/jnunemaker/plucky” rel=“nofollow”>提交一项拉动请求。 http://www.ruby-forum.com/topic/3319610“rel=“nofollow”>here 撰写hash

问题回答

暂无回答




相关问题
Selenium not working with Firefox 3.x on linux

I am using selenium-server , selenium rc for UI testing in my application . My dev box is Windows with FireFox 3.5 and every thing is running fine and cool. But when i try to run selenium tests on my ...

Best browser for testing under Safari Mobile on Linux?

I have an iPhone web app I m producing on a Linux machine. What s the best browser I can use to most closely mimic the feature-limited version of Safari present on the iPhone? (It s a "slimmed down" ...

Code Coverage Tools & Visual Studio 2008 Pro

Just wondering what people are using for code coverage tools when using MS Visual Studio 2008 Pro. We are using the built-in MS test project and unit testing tool (the one that come pre-installed ...

Is there any error checking web app cralwers out there?

Wondering if there was some sort of crawler we could use to test and re-test everything when changes are made to the web app so we know some new change didn t error out any existing pages. Or maybe a ...

热门标签