Giter Site home page Giter Site logo

flexmock's People

Contributors

esumerfd avatar jimweirich avatar julik avatar othatbrian avatar twp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flexmock's Issues

Unneeded shebang for tags.rake

tags.rake file has shebang (#!/usr/bin/env ruby).
If we would run like this ./tags.rake, the shebang is needed.
However if not, it might be better that the lines are removed.

After checking other *.rake files, I did not see shebang for the files.

https://github.com/jimweirich/flexmock/blob/master/rakelib/tags.rake#L1-L2

#!/usr/bin/env ruby
# -*- ruby -*-

Can you remove the lines?
Because I saw the warning message for flexmock RPM file on Fedora Project.
Thanks.

See https://en.wikipedia.org/wiki/Shebang_(Unix)

Object#methods(false) broken on new Rubies

I've found that new Rubies do not really love Object#methods(false) - it's not documented anymore, and delegates explode with it. Delegates that means also tempfiles and all the rest of the affair - which is actually pretty broken. Why don'y we replace it with singleton_methods? This gets rid of the problem.

I've filed an issue with ruby-core on delegates
http://redmine.ruby-lang.org/issues/4882

but in the meantime I've prepared a handy commit for you here
julik@4acea00

Here's what happens because of this problem:

  1. Error:
    test_write_larger_than_max_swaps_tempfile(TestBufferIO):
    ArgumentError: wrong number of arguments (1 for 0)
    /Users/julik/.rvm/gems/ruby-1.9.2-p180/gems/flexmock-0.9.0/lib/flexmock/partial_mock.rb:201:in singleton?' /Users/julik/.rvm/gems/ruby-1.9.2-p180/gems/flexmock-0.9.0/lib/flexmock/partial_mock.rb:236:instow_existing_definition'
    /Users/julik/.rvm/gems/ruby-1.9.2-p180/gems/flexmock-0.9.0/lib/flexmock/partial_mock.rb:92:in add_mock_method' /Users/julik/.rvm/gems/ruby-1.9.2-p180/gems/flexmock-0.9.0/lib/flexmock/partial_mock.rb:46:ininitialize'

Also, please be so kind to either fix your bug report form or disable the Issues tab here. Or both. Or disable the form and enable Issues. Or neither. Dunno.
http://www.picupine.com/629b3b8x

flexmock with minitest throws NoMethodError: undefined method `assertions'

Running

gem 'minitest'
require 'minitest/autorun'
require 'flexmock'
class TestMergeCommand <Minitest::Test
include FlexMock::TestCase
def test_execute
app = flexmock('app')
app.should_receive(:dummy).once
@model = Array.new
assert_nil(@model.index(app))
end
end

gives

Run options: --seed 27174

Running:

E
Finished in 0.001054s, 949.1800 runs/s, 949.1800 assertions/s.

  1. Error:
    TestMyClass#test_my_class:
    NoMethodError: undefined method assertions' for #<FlexMock::TestUnitFrameworkAdapter:0x000000013ea4d0> test/pry_test.rb:28:intest_my_class'
    1 runs, 1 assertions, 0 failures, 1 errors, 0 skips

Tested with

  • Ruby 1.9.3p448
  • flexmock 1.3.2
  • minitest-5.0.8

NoMethodError: undefined method `assertions'

I am receiving the following error:

NoMethodError: undefined method `assertions' for  #<FlexMock::TestUnitFrameworkAdapter:0x007fc7bd70c470>

When I try to run the following test:

 basket_mock = flexmock(@basket).should_receive(:discount_instance)
                     .with("promo")
                     .and_return(promo_mock)

On the code:

 def discount_from_codes(*types)
    return types.inject(0) do |result, element|
      if discount_instance(element)
        math = discount_instance(element).discount_for_basket(self)
      end
      result + math.to_f
    end
  end

When I change the variable to me "promo" it seems to run through correctly - is there an issue when trying to use flexmock with variable arguments as opposed to string arguments?

assert_block deprecated in minitest-2.12.0 and later

In MiniTest 2.12.0, assert_block was deprecated. Any expectation failure results in a deprecation warning coming from the super send at test_unit_integration.rb:53.

I had a brief look at how to fix it, but I wasn't sure of the best way to proceed. It would be possible to replace the implementation of TestFrameworkAdapter#assert_block with something like this:

assert(yield, message)

But I'm not sure if that provides the desired error message or not.

I'd be happy to work on a pull request given a little direction of the best approach to take.

License file?

Right now I am seeing flexmock's license is copy right.
However is it possible to decide your license type for that, and add the license file such as LICENSE.txt?

Because there are flexmock RPM package in Fedora project.
And I am going to contribute to flexmock's RPM package.
https://admin.fedoraproject.org/pkgdb/package/rpms/rubygem-flexmock/
It might be better for us to have license file.

Github also supporting license file.
Popular license is MIT in rubygem packages.
You might be able to add it easily from github web site.
https://help.github.com/articles/licensing-a-repository/

flexmock throws NameError when mocking a method created by method_missing and respond_to_missing?

I tried to report this issue on http://onestepback.org/cgi-bin/bugs.cgi?project=flexmock but i can't get passed the 'Please supply a detailed description of the bug report.' guard, so I'll try it here again:

When I mock a method that is created on the fly via method_missing and known to respond_to? because of the usage of respond_to_missing? (which got introduced with ruby 1.9) flexmock throws a NameError in the teardown once it is trying to realias the original methods. lib/flexmock/partial_mock.rb:280:in 'alias_method'

I changed your 'Creating Partial Mocks' example a bit, to show the exact error and the 'workaround' I came up with: https://gist.github.com/2368754

The "have_received" matcher needs a description method.

Using the "have_failed" matcher with flexmock invokes an RSpec warning. For example, the following spec:

require 'rspec/given'
require 'flexmock/rspec/configure'

class Dog
  def initialize(tail)
    @tail = tail
  end
  def happy
  end
end

describe Dog do
  Given(:tail) { flexmock() }
  Given(:fido) { Dog.new(tail) }
  When { fido.happy }
  Then { tail.should have_received(:wag).once }
end

gives the following output:

F

Failures:

  1) Dog should When you call a matcher in an example without a String, like this:

specify { object.should matcher }

or this:

it { should matcher }

RSpec expects the matcher to have a #description method. You should either
add a String to the example this matcher is being used in, or give it a
description method. Then you won't have to suffer this lengthy warning again.
     Failure/Error: Then { tail.should have_received(:wag).once }
       expected wag(...) to be received by <FlexMock:unknown> once.
       No messages have been received
     # /Users/jim/pgm/ruby/testexample/missing_description_spec.rb:16:in `block (2 levels) in <top (required)>'
     # /Users/jim/pgm/ruby/testexample/missing_description_spec.rb:16:in `block in Then'

Finished in 0.00042 seconds
1 example, 1 failure

Flexmock 0.8.11 seems to require Ruby 1.9.x or greater, readme says 1.8.x or greater

I installed Flexmock 0.8.11 and got the error

    partial_mock.rb:94: syntax error, unexpected ',', expecting '|' (SyntaxError)
      define_method(method_name) { |*args, &block|

when trying to start up my server (See Full Stack Trace Below.) I am using Ruby 1.8.6. I suspected the syntax error might be a difference between 1.8 and 1.9. So I installed and tried it with Ruby 1.9.1 and the server started up OK.

If there's an (easy) way to get it to work with Ruby 1.8 and 1.9, cool. If not, then I'd just change your README.rdoc to specify that Ruby 1.9.x or greater is required for this version of Flexmock, because currently it says 1.8.x is OK.

(Note, I downgraded my flexmock to 0.8.6 and that works for now. I don't know where the cutoff line for the Ruby 1.8 vs. 1.9 requirement between Flexmock 0.8.6 and 0.8.11. I didn't try once I got something working again :)

FULL STACK TRACE HERE:
c:/workspace/proctor_dev/vendor/rails/activesupport/lib/active_support/dependencies.rb:184:in require': C:/Ruby/lib/ruby/gems/1.8/gems/flexmock-0.8.1 1/lib/flexmock/partial_mock.rb:94: syntax error, unexpected ',', expecting '|' (SyntaxError) define_method(method_name) { |*args, &block| ^ C:/Ruby/lib/ruby/gems/1.8/gems/flexmock-0.8.11/lib/flexmock/partial_mock.rb:101: syntax error, unexpected '}', expecting kEND C:/Ruby/lib/ruby/gems/1.8/gems/flexmock-0.8.11/lib/flexmock/partial_mock.rb:295: syntax error, unexpected $end, expecting kEND from c:/workspace/proctor_dev/vendor/rails/activesupport/lib/active_support/dependencies.rb:184:inrequire'
from C:/Ruby/lib/ruby/gems/1.8/gems/flexmock-0.8.11/lib/flexmock/base.rb:22
from c:/workspace/proctor_dev/vendor/rails/activesupport/lib/active_support/dependencies.rb:184:in require' from c:/workspace/proctor_dev/vendor/rails/activesupport/lib/active_support/dependencies.rb:184:inrequire'
from C:/Ruby/lib/ruby/gems/1.8/gems/flexmock-0.8.11/lib/flexmock.rb:12
from C:/Ruby/lib/ruby/gems/1.8/gems/bundler-1.0.0/lib/bundler/runtime.rb:64:in require' from C:/Ruby/lib/ruby/gems/1.8/gems/bundler-1.0.0/lib/bundler/runtime.rb:64:inrequire'
from C:/Ruby/lib/ruby/gems/1.8/gems/bundler-1.0.0/lib/bundler/runtime.rb:62:in each' ... 12 levels... from c:/workspace/proctor_dev/vendor/rails/activesupport/lib/active_support/dependencies.rb:182:inrequire'
from c:/workspace/proctor_dev/vendor/rails/railties/lib/commands/server.rb:84
from script/server:3:in `require'
from script/server:3

Spying on objects without pre-defining any expectations

I would expect to be able to define a partial mock (i.e. flexmock(realobject)), use the object and then test against what messages were sent to the real object. Here's an example of what I mean using a flexmock on a class:

require 'spec_helper'

class Foo
  class << self
    attr_accessor :track_this_value
  end                     
end

describe "spying and passing through" do
  before { flexmock(Foo) }
  subject { Foo }
  before { Foo.track_this_value = "baz" }
  its(:track_this_value) { should == "baz" } # it passes through

  it "records methods on the mocked class" do
    Foo.should have_received(:track_this_value)
  end

end

The test does pass the its(:track_this_value) expectation, but not the should have_received. Instead I get:

  1) spying and passing through records methods on the mocked class
     Failure/Error: Foo.should have_received(:track_this_value)
       expected track_this_value(...) to be received by Foo.
       No messages have been received
     # ./spec/spy_spec.rb:16:in `block (2 levels) in <top (required)>'

Wrong "called incorrect number of times" error when multiple expectations are registered on the same method

First the error message ... which looks weird. It basically both says that a method has not been called, but this method signature can be found in the message list:

test_data_reader_creates_reader_on_associated_port(TC_RobyPlugin_TaskContext) [/home/doudou/dev/virgo/.gems/gems/flexmock-1.0.3/lib/flexmock/validators.rb:48]:
in mock 'mock for #Orocos::Spec::OutputPort:0x00000004196eb0': Method 'reader({:pull=>true, :type=>:buffer, :size=>20})' called incorrect number of times
1 call expected
0 matching calls found
The following messages have been received:
to_ary()
reader({:pull=>true, :type=>:buffer, :size=>20})

I set up two expectations on reader:

The first one is a catch-all

task.orogen_task.port("out").should_receive(:reader)

The second one is more specific

task.orogen_task.port("out").should_receive(:reader).with({:pull => true, :type => :buffer, :size => 20}).once

If I comment the first one, the error is reported. Otherwise, the test passes fine.

flexmock raises "undefined method 'teardown'" on minitest

require "minitest/autorun"
require 'flexmock/test_unit'

class SimpleTest < MiniTest::Unit::TestCase
  def test_flexmock
    flexmock()
  end
end

results in the following:

undefined method `teardown' for class `Test::Unit::TestCase' (NameError)
from D:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/flexmock-1.3.1/lib/flexmock/test_unit.rb:16:in `<module:Unit>'

This is the case for ruby1.9.3 and ruby2.0.0 with minitest 4.1.0

FlexMock no longer works with Minitest

Running flexmock 1.3.2 & Minitest 5.0.6

require 'minitest/autorun'
require 'flexmock/unit_test'

class TestFlexMock < Minitest::Test

  def test_this
    flexmock()
  end

end

results in

TestFlexMock#test_this:
NoMethodError: undefined method `flexmock' for #<TestFlexMock:0x00000101253c60>
    blah.rb:8:in `test_this'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.