Project

General

Profile

Actions

Bug #10603

closed

Ruby process memory is crashing

Added by pritamdey (arup rakshit) over 9 years ago. Updated over 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.1.4p265 (2014-10-27 revision 48166) [i686-linux]
[ruby-core:66868]

Description

I got one issue while I was writing tests in RSpec framework for my some ruby codes.

Issue I found, when I wrote the below code :

  describe "::add" do
    let(:item) { double(item) }

    it 'should store the item on the class' do
      subject.add(item)
      expect(subject.all).to include(item)
    end
  end

My complete code for which I was writing test :-

=========================
simple_store.rb
=========================
class SimpleStore
  def initialize(attributes = {})
    update(attributes)
  end

  def destroy
    self.class.remove(self)
    self.freeze
  end

  def update(attributes)
    attributes.each_pair do |attribute, value|
      self.public_send "#{attribute}=", value
    end
  end

  def save
    self.class.add(self)
  end

  def id
    self.class.items.key(self)
  end

  def self.add(item)
    items.store(next_id, item)
  end

  def self.all
    items.values
  end

  def self.create(*arguments)
    item = new(*arguments)
    add(item)
    item
  end

  def self.items
    @items ||= Hash.new
  end

  def self.get(id)
    items.fetch(id.to_i)
  end

  def self.remove(item)
    items.delete(item.id)
  end

  def self.next_id
    @next_id ||= 0
    @next_id += 1
  end
end

And the corresponding test :-

require 'rspec'
require './simple_store'

describe SimpleStore do
  describe 'instance methods' do
    let(:subject_class) { Class.new(described_class) }

    subject { subject_class.new }

    describe "#save" do
      it 'stores the item on the class' do
        subject.save
        expect(subject_class.all).to include(subject)
      end
    end

    describe "#destroy" do
      before do
        subject_class.add(subject)
      end

      it 'removes the item from the class storage' do
        subject.destroy
        expect(subject_class.all).not_to include(subject)
      end
    end

    describe "#id" do
      before do
        subject_class.add(subject)
      end

      it 'returns the key that has been saved to in the collection' do
        expect(subject.id).to eq(1)
      end
    end

    describe 'class methods' do
      subject { Class.new(described_class) }

      describe '::all' do
        it 'should  be empty until something has been added' do
          expect(subject.all).to be_empty
        end
      end

      describe "::add" do
        let(:item) { double(item) }

        it 'should store the item on the class' do
          subject.add(item)
          expect(subject.all).to include(item)
        end
      end

      describe "::create" do
        it 'should create a new item, store it into the class and return it' do
          new_item = subject.create
          expect(subject.all).to include(new_item)
        end
      end
    end
  end
end

=============
Here is some more details about my environment :-

[arup@to_do_app]$ ruby -v
ruby 2.1.4p265 (2014-10-27 revision 48166) [i686-linux]
[arup@to_do_app]$ gem list --local

*** LOCAL GEMS ***

bigdecimal (1.2.4)
bundler (1.7.4)
bundler-unload (1.0.2)
diff-lcs (1.2.5)
executable-hooks (1.3.2)
gem-wrappers (1.2.7)
io-console (0.4.2)
json (1.8.1)
minitest (4.7.5)
psych (2.0.5)
rack (1.5.2)
rack-protection (1.5.3)
rake (10.1.0)
rdoc (4.1.0)
rspec (3.1.0)
rspec-core (3.1.7)
rspec-expectations (3.1.2)
rspec-mocks (3.1.3)
rspec-support (3.1.2)
rubygems-bundler (1.4.4)
rvm (1.11.3.9)
sinatra (1.4.5)
test-unit (2.1.4.0)
tilt (1.4.1)
[arup@to_do_app]$

Please find the attached error file, which is I am getting due to the rspec spec/simple_store_spec.rb.


Files

error.txt (28.1 KB) error.txt pritamdey (arup rakshit), 12/16/2014 04:23 AM
Actions #1

Updated by jeremyevans0 (Jeremy Evans) over 4 years ago

  • Status changed from Open to Closed
Actions

Also available in: Atom PDF

Like0
Like0