Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create mocks for the integration tests so they can run under CI #8

Open
amclain opened this issue Jan 30, 2015 · 0 comments
Open

Create mocks for the integration tests so they can run under CI #8

amclain opened this issue Jan 30, 2015 · 0 comments

Comments

@amclain
Copy link
Owner

amclain commented Jan 30, 2015

Tests like this need to mock the call to the NetLinx compiler so they can be tested on a continuous integration platform without the need to install proprietary software. The real integration tests should still be available (and flagged as integration) so they can be run on a machine with the compiler installed.

it "compiles a .axs source code file" do
    files = test_file_generator.new 'source-file-plain'

    files.compiled_files.each do |file|
      # Delete any existing files.
      File.delete file if File.exists? file

      # Compiled files should not exist.
      File.exists?(file).should eq false
    end

    # Add source code file to the list of targets to compile.
    compilable.compiler_target_files << files.source_file

    # Run the compiler.
    compiler.compile compilable

    # Compiled files should exist.
    files.compiled_files.each do |file|
      File.exists?(file).should eq true
    end
  end if INTEGRATION_TEST

This is an example of how the call to the compiler was mocked:

describe "Wine" do
    let(:wine_path) { '~/.wine/drive_c/Program Files/Common Files/AMXShare/COM' }
    let(:source_file) { File.expand_path 'source-file-plain', 'spec/workspace/import-test' }
    let(:wine_command) { "wine \"#{File.expand_path('nlrc.exe', wine_path)}\" \"#{source_file}\"" }

    let(:io_double) {
      double().tap do |d|
        d.should_receive(:read) { '' }
        d.should_receive(:close)
      end
    }

    it "can execute the compiler" do
      # Add source code file to the list of targets to compile.
      compilable.compiler_target_files << source_file

      # Stub File.exists? to force Wine path.
      File.should_receive(:exists?).at_least(:once) do |path|
        path.include?('.wine') ? true : false
      end

      # Stub popen to check for correct command.
      IO.should_receive(:popen) do |cmd|
        cmd.should eq wine_command
        io_double
      end

      # Run the compiler.
      compiler.compile compilable
    end
  end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant