|
| 1 | +require 'spec_helper' |
| 2 | +require 'nanahoshi/info' |
| 3 | +describe Nanahoshi::Info do |
| 4 | + before do |
| 5 | + graph = { |
| 6 | + "libv8"=>[], "minitest"=>[], "turbolinks"=>["coffee-rails"], "tilt"=>[], "thread_safe"=>[], "thor"=>[], |
| 7 | + "therubyracer"=>["ref", "libv8"], "sprockets-rails"=>["sprockets", "actionpack", "activesupport"], |
| 8 | + "sprockets"=>["hike", "multi_json", "rack", "tilt"], "spring"=>[], "sdoc"=>["rdoc", "json"], |
| 9 | + "sass-rails"=>["sass", "railties", "sprockets-rails", "sprockets"], "sass"=>[], "ref"=>[], "rdoc"=>["json"], |
| 10 | + "rake"=>[], "railties"=>["activesupport", "actionpack", "rake", "thor"], |
| 11 | + "rails"=>["activesupport", "actionpack", "actionview", "activemodel", "activerecord", "actionmailer", "railties", "bundler", "sprockets-rails"], |
| 12 | + "rack-test"=>["rack"], "rack"=>[], "nanahoshi"=>["rails"], "multi_json"=>[], "tzinfo"=>["thread_safe"], |
| 13 | + "mime-types"=>[], "mail"=>["mime-types"], "uglifier"=>["execjs", "json"], "json"=>[], |
| 14 | + "jquery-rails"=>["railties", "thor"], "jbuilder"=>["activesupport", "multi_json"], "i18n"=>[], "hike"=>[], |
| 15 | + "execjs"=>[], "erubis"=>[], "coffee-script-source"=>[], "coffee-script"=>["coffee-script-source", "execjs"], |
| 16 | + "coffee-rails"=>["coffee-script", "railties"], "bundler"=>[], "builder"=>[], "arel"=>[], |
| 17 | + "activesupport"=>["i18n", "json", "tzinfo", "minitest", "thread_safe"], |
| 18 | + "activerecord"=>["activesupport", "activemodel", "arel"], "activemodel"=>["activesupport", "builder"], |
| 19 | + "actionview"=>["activesupport", "builder", "erubis"], |
| 20 | + "actionpack"=>["activesupport", "rack", "rack-test", "actionview"], |
| 21 | + "actionmailer"=>["actionpack", "actionview", "mail"] |
| 22 | + } |
| 23 | + allow(Nanahoshi::Info).to receive(:load_graph).and_return(graph) |
| 24 | + end |
| 25 | + it "load nodes array and edges array" do |
| 26 | + expected_nodes = [ |
| 27 | + {:name=>"libv8", :type=>[:end_leaf]}, {:name=>"minitest", :type=>[:end_leaf]}, |
| 28 | + {:name=>"turbolinks", :type=>[:start_leaf]}, {:name=>"tilt", :type=>[:end_leaf]}, |
| 29 | + {:name=>"thread_safe", :type=>[:end_leaf]}, {:name=>"thor", :type=>[:end_leaf]}, |
| 30 | + {:name=>"therubyracer", :type=>[:start_leaf]}, {:name=>"sprockets-rails", :type=>[]}, |
| 31 | + {:name=>"sprockets", :type=>[]}, {:name=>"spring", :type=>[:start_leaf, :end_leaf]}, |
| 32 | + {:name=>"sdoc", :type=>[:start_leaf]}, {:name=>"sass-rails", :type=>[:start_leaf]}, |
| 33 | + {:name=>"sass", :type=>[:end_leaf]}, {:name=>"ref", :type=>[:end_leaf]}, {:name=>"rdoc", :type=>[]}, |
| 34 | + {:name=>"rake", :type=>[:end_leaf]}, {:name=>"railties", :type=>[]}, {:name=>"rails", :type=>[]}, |
| 35 | + {:name=>"rack-test", :type=>[]}, {:name=>"rack", :type=>[:end_leaf]}, |
| 36 | + {:name=>"nanahoshi", :type=>[:start_leaf]}, {:name=>"multi_json", :type=>[:end_leaf]}, |
| 37 | + {:name=>"tzinfo", :type=>[]}, {:name=>"mime-types", :type=>[:end_leaf]}, {:name=>"mail", :type=>[]}, |
| 38 | + {:name=>"uglifier", :type=>[:start_leaf]}, {:name=>"json", :type=>[:end_leaf]}, |
| 39 | + {:name=>"jquery-rails", :type=>[:start_leaf]}, {:name=>"jbuilder", :type=>[:start_leaf]}, |
| 40 | + {:name=>"i18n", :type=>[:end_leaf]}, {:name=>"hike", :type=>[:end_leaf]}, {:name=>"execjs", :type=>[:end_leaf]}, |
| 41 | + {:name=>"erubis", :type=>[:end_leaf]}, {:name=>"coffee-script-source", :type=>[:end_leaf]}, |
| 42 | + {:name=>"coffee-script", :type=>[]}, {:name=>"coffee-rails", :type=>[]}, {:name=>"bundler", :type=>[:end_leaf]}, |
| 43 | + {:name=>"builder", :type=>[:end_leaf]}, {:name=>"arel", :type=>[:end_leaf]}, {:name=>"activesupport", :type=>[]}, |
| 44 | + {:name=>"activerecord", :type=>[]}, {:name=>"activemodel", :type=>[]}, {:name=>"actionview", :type=>[]}, |
| 45 | + {:name=>"actionpack", :type=>[]}, {:name=>"actionmailer", :type=>[]} |
| 46 | + ] |
| 47 | + expected_edges = [ |
| 48 | + {:source=>2, :target=>35}, {:source=>6, :target=>13}, {:source=>6, :target=>0}, {:source=>7, :target=>8}, |
| 49 | + {:source=>7, :target=>43}, {:source=>7, :target=>39}, {:source=>8, :target=>30}, {:source=>8, :target=>21}, |
| 50 | + {:source=>8, :target=>19}, {:source=>8, :target=>3}, {:source=>10, :target=>14}, {:source=>10, :target=>26}, |
| 51 | + {:source=>11, :target=>12}, {:source=>11, :target=>16}, {:source=>11, :target=>7}, {:source=>11, :target=>8}, |
| 52 | + {:source=>14, :target=>26}, {:source=>16, :target=>39}, {:source=>16, :target=>43}, {:source=>16, :target=>15}, |
| 53 | + {:source=>16, :target=>5}, {:source=>17, :target=>39}, {:source=>17, :target=>43}, {:source=>17, :target=>42}, |
| 54 | + {:source=>17, :target=>41}, {:source=>17, :target=>40}, {:source=>17, :target=>44}, {:source=>17, :target=>16}, |
| 55 | + {:source=>17, :target=>36}, {:source=>17, :target=>7}, {:source=>18, :target=>19}, {:source=>20, :target=>17}, |
| 56 | + {:source=>22, :target=>4}, {:source=>24, :target=>23}, {:source=>25, :target=>31}, {:source=>25, :target=>26}, |
| 57 | + {:source=>27, :target=>16}, {:source=>27, :target=>5}, {:source=>28, :target=>39}, {:source=>28, :target=>21}, |
| 58 | + {:source=>34, :target=>33}, {:source=>34, :target=>31}, {:source=>35, :target=>34}, {:source=>35, :target=>16}, |
| 59 | + {:source=>39, :target=>29}, {:source=>39, :target=>26}, {:source=>39, :target=>22}, {:source=>39, :target=>1}, |
| 60 | + {:source=>39, :target=>4}, {:source=>40, :target=>39}, {:source=>40, :target=>41}, {:source=>40, :target=>38}, |
| 61 | + {:source=>41, :target=>39}, {:source=>41, :target=>37}, {:source=>42, :target=>39}, {:source=>42, :target=>37}, |
| 62 | + {:source=>42, :target=>32}, {:source=>43, :target=>39}, {:source=>43, :target=>19}, {:source=>43, :target=>18}, |
| 63 | + {:source=>43, :target=>42}, {:source=>44, :target=>43}, {:source=>44, :target=>42}, {:source=>44, :target=>24} |
| 64 | + ] |
| 65 | + nodes, edges = Nanahoshi::Info.nodes_and_edges |
| 66 | + |
| 67 | + expect(nodes).to eq expected_nodes |
| 68 | + expect(edges).to eq expected_edges |
| 69 | + end |
| 70 | +end |
0 commit comments