Project

General

Profile

Actions

Defect #40603

closed

Mocha 2.2.0 causes test failure: "unexpected invocation"

Added by Go MAEDA 8 months ago. Updated 8 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Gems support
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

After updating Mocha from version 2.1.0 to 2.2.0, a test began to fail with the following output:

$ bin/rails test test/unit/issue_test.rb:704

Run options: --seed 38306

# Running:

F

Failure:
IssueTest#test_assigning_attributes_should_assign_project_and_tracker_first [app/models/issue.rb:478]:
unexpected invocation: subject=(Test)

bin/rails test test/unit/issue_test.rb:704
Actions #1

Updated by Go MAEDA 8 months ago

  • Category changed from Gems support to Code cleanup/refactoring

Below is the test code that currently fails. The three lines of issue.expects expect that the three methods :project_id=, :tracker_id=, and :subject= are called in this order. However, it is :subject= that is called first because issue.attributes = {:subject => 'Test'} is executed first. It is curious that this code worked with Mocha 2.1.

  def test_assigning_attributes_should_assign_project_and_tracker_first
    seq = sequence('seq')
    issue = Issue.new
    issue.expects(:project_id=).in_sequence(seq)
    issue.expects(:tracker_id=).in_sequence(seq)
    issue.expects(:subject=).in_sequence(seq)
    assert_raise Exception do
      issue.attributes = {:subject => 'Test'}
    end
    assert_nothing_raised do
      issue.attributes = {:tracker_id => 2, :project_id => 1, :subject => 'Test'}
    end
  end

The error can be fixed simply removing issue.attributes = {:subject => 'Test'}.

diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb
index 599c0046d..21a295aa1 100644
--- a/test/unit/issue_test.rb
+++ b/test/unit/issue_test.rb
@@ -707,9 +707,6 @@ class IssueTest < ActiveSupport::TestCase
     issue.expects(:project_id=).in_sequence(seq)
     issue.expects(:tracker_id=).in_sequence(seq)
     issue.expects(:subject=).in_sequence(seq)
-    assert_raise Exception do
-      issue.attributes = {:subject => 'Test'}
-    end
     assert_nothing_raised do
       issue.attributes = {:tracker_id => 2, :project_id => 1, :subject => 'Test'}
     end
Actions #2

Updated by Go MAEDA 8 months ago

  • Category changed from Code cleanup/refactoring to Gems support
  • Status changed from New to Resolved
  • Assignee set to Go MAEDA
  • Target version set to 5.0.9
  • Resolution set to Fixed
Actions #3

Updated by Go MAEDA 8 months ago

  • Status changed from Resolved to Closed

Committed the fix in r22789.

Actions

Also available in: Atom PDF