{"action":"closed","issue":{"url":"https://api.github.com/repos/rspec/rspec-mocks/issues/1011","labels_url":"https://api.github.com/repos/rspec/rspec-mocks/issues/1011/labels{/name}","comments_url":"https://api.github.com/repos/rspec/rspec-mocks/issues/1011/comments","events_url":"https://api.github.com/repos/rspec/rspec-mocks/issues/1011/events","html_url":"https://github.com/rspec/rspec-mocks/issues/1011","id":106239524,"number":1011,"title":"Request for help to clean custom DSL","user":{"login":"fgarcia","id":253157,"avatar_url":"https://avatars.githubusercontent.com/u/253157?v=3","gravatar_id":"","url":"https://api.github.com/users/fgarcia","html_url":"https://github.com/fgarcia","followers_url":"https://api.github.com/users/fgarcia/followers","following_url":"https://api.github.com/users/fgarcia/following{/other_user}","gists_url":"https://api.github.com/users/fgarcia/gists{/gist_id}","starred_url":"https://api.github.com/users/fgarcia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fgarcia/subscriptions","organizations_url":"https://api.github.com/users/fgarcia/orgs","repos_url":"https://api.github.com/users/fgarcia/repos","events_url":"https://api.github.com/users/fgarcia/events{/privacy}","received_events_url":"https://api.github.com/users/fgarcia/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-09-13T20:57:50Z","updated_at":"2015-09-14T08:07:39Z","closed_at":"2015-09-14T08:07:39Z","body":"I am trying to write a custom DSL to do some \"unethical\" hack in my classes. Basically I want to prevent the definition of mocks/stubs in my specs and instead define named mocks/stubs directly into my classes. Something like this:\r\n\r\n    class Person\r\n      attr_reader :name\r\n      attr_reader :mood\r\n\r\n      def initialize(name, mood = 'happy')\r\n        @name = name\r\n        @mood = mood\r\n      end\r\n\r\n      stubs do\r\n        def grumpy\r\n          allow.to receive(:mood) { 'grumpy' }\r\n        end\r\n      end\r\n    end\r\n\r\nNow in my Specs I can have named stubs like this:\r\n\r\n    describe Person do\r\n      it 'demo' do\r\n        expect(subject.name).to eq \"fran_1\"\r\n        expect(subject.mood).to eq \"happy\"\r\n\r\n        subject.stub! self, :grumpy\r\n        expect(subject.mood).to eq \"grumpy\"\r\n      end\r\n    end\r\n\r\n\r\nThis is my current DSL code:\r\n\r\n    module StubsDSL\r\n      Stubs = Module.new\r\n      def self.stubs(&block)\r\n        Stubs.module_eval(&block)\r\n        extend Stubs\r\n      end\r\n      \r\n      def stub!(who, method, *args)\r\n        this = self\r\n        unbound = Stubs.instance_method method\r\n        who.instance_eval do\r\n          @this = this\r\n          def allow\r\n            super(@this)\r\n          end\r\n          unbound.bind(who).call\r\n        end\r\n      end\r\n    end\r\n\r\n\r\n\r\nI've been exploring rspec-mocks source code, but I am a bit lost between Proxy / Space objects and how everything works together.  Above all things I want to monkey patch Rspec to replace the old #stub implemention without the warnings. Something like this:\r\n\r\n     subject.stub :grumpy\r\n\r\nI also believe the function `stub!(who, method, *args)` could be moved somewhere else like inside RSpec::Mocks::Syntax, but I am not sure how\r\n\r\nAny help would be greatly welcome!\r\n\r\nI know this sounds like a quite dirty hack, but I am trying to learn more about Rspec internals and test some ideas"}}