Sha256: 3e17320716802d850186585ce03dccc39bf3f8f8e13af6f6850488edbee39604

Contents?: true

Size: 1.21 KB

Versions: 302

Compression:

Stored size: 1.21 KB

Contents

require 'helper'
require 'fileutils'
require 'tmpdir'

describe 'SwotCollectionMethods' do
  before do
    @tmp_dir = Dir.mktmpdir "swot-test"
    Swot.instance_variable_set(:@domains_path, @tmp_dir)
    write_domain_file "students.texas.edu"
    write_domain_file "mit.edu"
  end

  after do
    FileUtils.remove_entry @tmp_dir
  end

  def write_domain_file(domain, school_name = 'The University')
    parts = domain.split('.').reverse
    parts.last.concat('.txt')
    path = Pathname.new(@tmp_dir).join(*parts)
    path.dirname.mkpath
    path.open('w') { |f| f.puts school_name }
  end

  describe 'all_domains' do
    it 'gets all domains from files on disk' do
      all_domains = Swot.all_domains
      assert_equal all_domains.size, 2
      assert_includes all_domains, "students.texas.edu"
      assert_includes all_domains, "mit.edu"
    end
  end

  describe 'each_domain' do
    it 'yields a swot instance for every domain file' do
      domains = []
      Swot.each_domain { |d| domains << d }
      assert_equal domains.size, 2
      assert_equal true, domains.all?{ |d| d.is_a? Swot }
      assert_includes domains.map(&:to_s), "students.texas.edu"
      assert_includes domains.map(&:to_s), "mit.edu"
    end
  end
end

Version data entries

302 entries across 302 versions & 3 rubygems

Version Path
swot-ruby-1.0.5.20250313 test/test_collection_methods.rb
swot-ruby-1.0.5.20250303 test/test_collection_methods.rb
swot-ruby-1.0.5.20250301 test/test_collection_methods.rb
swot-ruby-1.0.5.20250226 test/test_collection_methods.rb
swot-ruby-1.0.5.20250225 test/test_collection_methods.rb
swot-ruby-1.0.5.20250224 test/test_collection_methods.rb
swot-ruby-1.0.5.20250220 test/test_collection_methods.rb
swot-ruby-1.0.5.20250215 test/test_collection_methods.rb
swot-ruby-1.0.5.20250211 test/test_collection_methods.rb
swot-ruby-1.0.5.20250208 test/test_collection_methods.rb
swot-ruby-1.0.5.20250206 test/test_collection_methods.rb
swot-ruby-1.0.5.20250204 test/test_collection_methods.rb
swot-ruby-1.0.5.20250203 test/test_collection_methods.rb
swot-ruby-1.0.5.20250202 test/test_collection_methods.rb
swot-ruby-1.0.5.20250129 test/test_collection_methods.rb
swot-ruby-1.0.5.20250128 test/test_collection_methods.rb
swot-ruby-1.0.5.20250126 test/test_collection_methods.rb
swot-ruby-1.0.5.20250125 test/test_collection_methods.rb
swot-ruby-1.0.5.20250124 test/test_collection_methods.rb
swot-ruby-1.0.5.20250122 test/test_collection_methods.rb