File: show_model_spec.rb

package info (click to toggle)
ruby-pry-rails 0.3.9-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 320 kB
  • sloc: ruby: 844; makefile: 4
file content (55 lines) | stat: -rw-r--r-- 1,364 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# encoding: UTF-8

require 'spec_helper'

describe "show-model" do
  it "should print one ActiveRecord model" do
    output = mock_pry('show-model Beer', 'exit-all')

    expected = <<MODEL
Beer
  id: integer
  name: string
  type: string
  rating: integer
  ibu: integer
  abv: integer
  belongs_to :hacker
MODEL

    output.must_equal expected
  end

  if defined? Mongoid
    it "should print one Mongoid model" do
      output = mock_pry('show-model Artist', 'exit-all')

      expected = <<MODEL
Artist
  _id: BSON::ObjectId
  name: String
  embeds_one :beer (validate)
  embeds_many :instruments (validate)
MODEL

      output.gsub!(/^ *_type: String\n/, '') # mongoid 3.0 and 3.1 differ on this
      output.gsub!(/Moped::BSON/, 'BSON')    # mongoid 3 and 4 differ on this
      output.must_equal expected
    end
  end

  it "should print an error if the model doesn't exist" do
    output = mock_pry('show-model FloojBulb', 'exit-all')
    output.must_equal "Couldn't find model FloojBulb!\n"
  end

  it "should print an error if it doesn't know what to do with the model" do
    output = mock_pry('show-model PryRails', 'exit-all')
    output.must_equal "Don't know how to show PryRails!\n"
  end

  it "should print help if no model name is given" do
    output = mock_pry('show-model', 'exit-all')
    output.must_match(/Usage: show-model/)
  end
end