jeudi 28 mai 2020

Set request header in integration test with Rails

I'm using session and I call it like this:

test_helper

  get_session()
   open_session
  end 

propertyController class

 current_session = get_session 
 current_session.get "/properties/"

I now need to figure out how to include an access token in the request header like request["header-name"] = token. I need this to be included in the open_session before it's returns. Is there a way to call request in an integration test without it being nul?

Best way to architect test development in Python so that tests can be run either with a mock or without a mock?

I'm starting a fresh python project and I want to write unit and integration tests with mocking and stubbing. However, I would like to run these tests during the build-pipeline against actual services by spawning these dependent services in a docker container. What is the best way to architect my project so that I can easily enable and disable mocking so that:

  • tests are run with mocks in local branches
  • tests are run with actual services (with mocks disabled) in CI build pipeline

I'm using python3 and pytest for my purposes.

Travis CI build process - TypeScript catching an error before Mocha does

This isn't so much a bug as the TypeScript compiler doing its job, however it is causing my Travis builds to fail.

In my package I have a function completeRound which takes a number as its first argument, then 3 optional arguments, and because I've written it in TypeScript I tell it that it needs to have a number passed in as the first argument:

function completeRound( number: number, rounding = 1, direction = 'closest', offset = 0 ): number {
  let n: number = +number,
      r: number = Math.abs(+rounding),
      d: string = direction,
      o: number = +offset;

  if (typeof n !== 'number') {
    throw new TypeError('You need to round a number!');
  }

  // Rest of the code goes here
}

It all works fine, the only trouble is when it comes to testing. In my testing script I have:

import completeRound from '../src/completeRound';
import { expect } from 'chai';
import 'mocha';

const expectedResults = [
  {
    testVal : {
      number    : 3.5,
      rounding  : 1,
      direction : 'down'
    },
    eR      : 3
  },
  // 40-something different tests, all passing fine
];

expectedResults.map(t => describe(`completeRound(${t.testVal.number}, ${t.testVal.rounding}, '${t.testVal.direction}', ${t.testVal.offset})`,() => {
  it(`should return ${t.eR}`, () => {
    const result = completeRound(t.testVal.number,t.testVal.rounding,t.testVal.direction,t.testVal.offset);
    expect(result).to.equal(t.eR);
  });
})); // For testing results where it shouldn't throw an error

/* This one is the problem line */
expect(() => completeRound([5])).to.throw(TypeError, /a number/);
/* ---------------------------- */

expect(() => completeRound(5,1,'arriba')).to.throw(Error, /valid rounding direction/);

So I'm passing it an array instead of a number, where I want JavaScript to throw the TypeError. Obviously I want people using this either in JavaScript or in TypeScript to be equally covered. Plus I'm after that sweet 100% figure in my coverage report. BUT, from the below report in Travis, we can see that the TypeScript compiler is getting there first and throwing a compilation error.

TSError: ⨯ Unable to compile TypeScript:

dev/test/completeRound.spec.ts:414:28 - error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'number'.

414 expect(() => completeRound([5])).to.throw(TypeError, /a number/);

I don't see a way that I can test the compiled code because that means, well, compiling it, I'm using webpack to compile it which straightaway put it in my ./dist folder, browserifies it and everything else, so I can't see how to import from that, and I don't really want a 2-step process where I compile it then bundle it.

I guess the short version is, I want to test JavaScript error throwing for an error where TypeScript would catch it automatically, but JavaScript wouldn't.

Can anyone help?

Wrapper.html() only shows the first element

I am currently testing my Vue component.

I have this as my test:

describe("tests", () => {
  wrapper = mount(myVueComponent, {
    propsData: {
      name: "required",
      fullscreen: "true"
    }
  });

  it("fullscreen on", () => {
    expect(wrapper.vm.fullscreenElement).toBeFalsy();
    console.log(wrapper.vm.html());
    wrapper.vm.onFullscreen(); // this method checks one of the child components which is not visible in my wrapper..
  })
});

When I try wrapper.vm.html() I get:

<div class="siDialog">
  <!---->
</div>

But in my component template there children elements where, is now. How do I get the whole template in my test?

Best way to test a webapp on different versions of iOS/Safari?

I have a very simple requirement that I am sure is shared by many developers out there. I want to be able to test and debug HTML5 webapps on different versions of iOS/Safari without having to buy a load of old Apple hardware. I have tried simulators on OSX/XCODE but these run so slowly that they are almost unusable. I have tried online simulators but these seem to lack features that enable you to do basic debugging so are useless to me.

It seems to me that the simplest thing that could work would be a browser that you could configure to use different versions of the Webkit engine. So you would need to be able to download a bunch of old versions of the Webkit engine and have some way of switching between these. You would then need some way of mapping OSX|iOS/Safari versions to Webkit versions so that you could quickly reproduce bugs and debug them. So the browser would need to have Dev Tools too.

Do you know if anyone has done anything like this already? Or can you think of some better solution to this problem?

How to get FindElementByAccessibilityId to find an Id inside a tabitem

I'm using Appium UI testing, and its fine until I try to find an element inside a tabitem. It generates the error 'An element could not be located on the page using the given search parameters.'

I've tried this:

var ucMedusa3D = session.FindElementByAccessibilityId("ucMedusa3D"); // doesn't work      

and this:

var tabMedusa3D = session.FindElementByAccessibilityId("tabMedusa3D"); // works
var ucMedusa3D = tabMedusa3D.FindElementByAccessibilityId("ucMedusa3D"); // doesn't work

n.b. session is the WindowsDriver variable and is set up correctly.

I can find other elements, but not if they are inside a tabitem.

Add value from Code section under WelcomeLabel2 of .isl file Inno Setup

In a Inno Script I have set a string constant under [Code] section. I use that constant to compare with a registry value to check if the version installed is the same. What I would like to have is to have this constant also displayed at the Welcome page of the setup under WelcomeLabel2. In my script I have created a [Message] section where I can change the text. How can I add the value of the constant in this label? I see that in the default.isl they are referring to [name/ver]. I cannot seem to find any info about it.

[Messages] //Change the WelcomeLabel2 text as specified in .isl file WelcomeLabel2=This will install [name] for xxxx on your computer.%n%nIt is recommended that you close all other applications before continuing.